Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identifying the exception value 1

Status
Not open for further replies.

siftach

Programmer
Jul 22, 2003
78
IL
I am using the try/catch method to trap exceptions. How can I find out what kind of an exception I get with catch (...), and how can I get the exception's related data?
 
it depends, if you're using your own exception class then simply use something like this:

try
{
if (...)
throw CMyException( error_code );

}
catch( CMyException &e )
{
e.HandleError();
}

basicly exceptions work like this


try
{
if ( something goes wrong )
throw 4;
}
catch( int code )
{
switch( code )
{
case 4:
WOW!
break;

...
}
}



 
just to add one more thing

If the exception-declaration statement is an ellipsis (...), the catch clause handles any type of exception, including C exceptions as well as system-generated and application-generated exceptions. This includes exceptions such as memory protection, divide-by-zero, and floating-point violations. An ellipsis catch handler must be the last handler for its try block.

(msdn)
 
I don't think you can identify in code which exception was caught by the catch(...). You should look at the code that is being called and identify potential exceptions, then catch those separately.

You should also use the debugger if you are having a specific problem, since you can edit the exceptions options to always stop on any exception that can be caught be a catch(...).
 
If you have RTTI information enabled, you might(should?) be able to use va_args (for the ... expansion) and be able to determine the exceptions type and handle the ones you want.

More information on RTTI is here:

Disclaimer: I've never attempted this, so if it works, great. If it doesn't work, well then sorry about your luck. Please let me know one way or the other, though. :)
 
10x necroleak, this is what I was looking for, and the MSDN documentation even led me to GetExceptionInformation(), which is exactly what I need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top