Re: multiple catch types
* Nick Keighley:
Hi,
I have, unsuccessfully, checked the net and Stroustrup before I
posted here.
Is there a way to catch multiple exception types in a single catch
statement?
Something like:
try
{
something();
}
catch (T1& T2& e)
{
cerr << "exception! " << e.what();
}
Perhaps it's expecting a bit much of the compiler.
T1 and T2 do not have a common base class.
If you don't need any information you can do
void foo()
{
try { something(); }
catch( ... ) { sayOops(); }
}
If you're using, say, two libraries each with non-standard exceptions, then in
the nearest enclosing code -- your library interface routines -- consider
exception tranlation, like
void translateLibExceptions()
{
try { throw; }
catch( LibAException const& x )
{
throw std::runtime_error( "Lib A exception" );
}
catch( LibBException const& x )
{
throw std::runtime_error( "Lib B exception" );
}
}
void foo()
{
try { something(); }
catch( ... ) { translateLibExceptions(); }
}
I tried reading the syntax but got a bit lost. Is there an electronic
version of the C++ syntax available somewhere? (I found one
HTML version but it appeared to be only almost-C++).
Google.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?