Catching unknown exceptions

B

Bryan

I have an unknown error in some legacy code. I can catch it with catch
(...), but I cannot tell what kind of error it is.

Is there any base exception class (like in java) that I can try and
catch that might give me some more meaningful information? Or
suggestions on the most common exceptions so I can just try them?

Thanks,
Bryan
 
I

Ian

Bryan said:
I have an unknown error in some legacy code. I can catch it with catch
(...), but I cannot tell what kind of error it is.

Is there any base exception class (like in java) that I can try and
catch that might give me some more meaningful information? Or
suggestions on the most common exceptions so I can just try them?
std::exception

Ian
 
B

benben

std::exception

Not necessarily!

A short answer to OP's question is: "There's no way you can do that".

A slightly longer answer is, if you don't know what exception is being
thrown after consulting all documentation, then it is better to:
- not catching the exception at all, or
- catch it but not to deal with the object being thrown.

Of course, if you are debugging, that's a different story. Your development
tools should have some function to pierce into the exception object
internals.

Ben
 
G

Greg

Bryan said:
I have an unknown error in some legacy code. I can catch it with catch
(...), but I cannot tell what kind of error it is.

Is there any base exception class (like in java) that I can try and
catch that might give me some more meaningful information? Or
suggestions on the most common exceptions so I can just try them?

Thanks,
Bryan

The ellipsis indicates that the catch clause doesn't care what kind of
exception it has caught. Its purpose is to to catch every exception. By
the time this catch clause executes, it's too late to wonder what kind
of exception was thrown. Because if the thrown type really were of
interest, it should have already been caught.

Generally, when the type of a thrown exception can vary, a C++ program
will declare a series of catch clauses with the ellipsis catch-all
coming last:

catch (std::exception& InException)
{
...
}

catch (int inOSErr)
{
...
}

catch (...) // for thrown types not already caught
{
...
}

Greg
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top