| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Bryan" |
| Date: |
23 Sep 2005 10:21:05 PM |
| Object: |
Catching unknown exceptions |
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
.
|
|
| User: "Greg" |
|
| Title: Re: Catching unknown exceptions |
24 Sep 2005 04:51:45 AM |
|
|
Bryan wrote:
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
.
|
|
|
|
| User: "Ian" |
|
| Title: Re: Catching unknown exceptions |
23 Sep 2005 10:40:04 PM |
|
|
Bryan wrote:
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
.
|
|
|
| User: "benben read backward" |
|
| Title: Re: Catching unknown exceptions |
24 Sep 2005 03:31:20 AM |
|
|
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
.
|
|
|
|
|

|
Related Articles |
|
|