K
Khuong Dinh Pham
How can i get more information about the exception when using catch(...)?
Thx in advance
Thx in advance
You can't.Khuong said:How can i get more information about the exception when using catch(...)?
Khuong said:How can i get more information about the exception when using catch(...)?
Thx in advance
How can i get more information about the exception when using catch(...)?
* Khuong Dinh Pham:
You can rethrow the exception (using "throw;") and catch it again with more
specific catch clauses.
Of course, if you're going to do that you might as well catch the specific
exceptions in the first place... Unless I'm missing something important,
which is entirely possible.
Alf said:* Owen Jacobson:
Yes, the possibility of centralizing the exception type determination and
relevant info extraction in a function, thus reducing code redundancy.
Alf said:* Owen Jacobson:
Yes, the possibility of centralizing the exception type determination and
relevant info extraction in a function, thus reducing code redundancy.
hmm. that sounds like something I want to do. Could you expand on this
a bit?
I'd like to put a bit long list of catches in a function but quite see
how to
do that.
Why would I need to catch the exception in the first place if the only thing
to do with it is to throw it again?
It goes like this, off the cuff:
std::string exceptionText()
{
try
{
throw;
}
catch( unsigned x )
{
return "tulso tones exception #" + stringFrom( x );
}
catch( CExpectNot* pOuch )
{
std::string const result =
"Mucho Fishy Casserole exception: " + pOuch->Massage();
pOuch->Destroy();
return result;
}
catch( std::exception const& x )
{
return x.what();
}
catch( ... )
{
return "Unknown exception";
}
}
void foo()
{
try
{
lib1Func(); lib2Func(); lib3Func();
}
catch( ... )
{
throw std::runtime_error( exceptionText() );
}
}
and then bar(), similar, and so on.
2. A variant of this idiom has recently been posted here:
http://article.gmane.org/gmane.comp.lib.boost.devel/132551
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.