Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Catching unknown exceptions

Reply
Thread Tools

Catching unknown exceptions

 
 
Bryan
Guest
Posts: n/a
 
      09-24-2005
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
 
Reply With Quote
 
 
 
 
Ian
Guest
Posts: n/a
 
      09-24-2005
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
 
Reply With Quote
 
 
 
 
benben
Guest
Posts: n/a
 
      09-24-2005
> 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


 
Reply With Quote
 
Greg
Guest
Posts: n/a
 
      09-24-2005

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Catching an unknown error Harlin Seritt Python 7 03-23-2007 01:48 PM
Catching unhandled exceptions using HttpModules Amil Hanish ASP .Net 0 04-12-2006 11:51 PM
Re: Catching exceptions that are never thrown Adam Maass Java 5 07-22-2003 10:58 PM
Re: Catching exceptions that are never thrown Mike Schilling Java 2 07-16-2003 08:36 PM
Re: catching exceptions from web user controls Marina ASP .Net 2 07-08-2003 04:48 PM



Advertisments