Re: Getting the exception object within catch(...)

From: Alf P. Steinbach (alfps_at_start.no)
Date: 12/04/03


Date: Thu, 04 Dec 2003 04:29:01 GMT

On Wed, 3 Dec 2003 22:26:21 +0100, "Jacek Dziedzic" <jacek_NO-SPAM_@janowo.net> wrote:

> Hi!
>
> In my main() function I have a last-resort exception construct that
>looks
>like this:
>
>int main() {
> try {
> // ... program code
> }
> catch(...) { // catch every exception
> std::cout << "An exception occured!" << std::endl;
> };
>};
>
> It works fine, but I never know *which* exception has occured.
>I seem to remember you can catch an exception object rather than
>an exception class, and then, having the precise object you could
>get the name that's stored somewhere inside it. But the "..." seems
>to get in the way for me. Is there a way to catch a precise exception
>object with catch(...)? Or a workaround for that?

Cy Edmunds and others have already answered the real question.

Now here's an answer to the literal question.

In many cases (actually, most cases of real software) you will have to
deal with non-standard exceptions of various kinds from a number of libraries.
Using try-catch-catch-catch everywhere is then redundant and a maintainance
nightmare. So instead you'd like to use catch(...) and _translate_ that
exception, whatever it may be, to a common form.

In standard C++ you can do that by rethrowing the exception and recatching
the exception within the catch(...), where this rethrowing and recatching is
performed by a common exception translation function (which must know about
all the most common kinds of exceptions in the application).

This technique does not work with some older compilers. In particular, a
compiler bug in Visual C++ prevented using this technique with earlier
incantations of that compiler.



Relevant Pages

  • Re: raritetclassic.com - Rare classical music
    ... (with exception of Czechs), most of the Asia ... I think it would be nicer if the guy would post link ... He does not sell recordings and it is not his agenda to ... I do not see why you will not find a common ...
    (rec.music.classical.recordings)
  • Re: Wow! Its a Yogh!
    ... "swamp" would then be an exception. ... I have never encountered before now any such claim like this about the sound "blocking" the sound change of a short-o that is common in "wa-" words. ...
    (sci.lang)
  • Re: Find rare bugs - SEH and c++ exception handling
    ... Such pain is more common than any of us would like to admit. ... cause is often a bad pointer or code that cleans up an array ... When the kernel detects an application exception, ... The bug is not reproducible and occours without user interaction (there ...
    (microsoft.public.pocketpc.developer)
  • Re: Win Vista and PBWIN
    ... This is the code i'm using which works under up same compiler. ... DIM cc AS choosecolorapi ... Exception Offset: 00029a85 ... Which common dialog? ...
    (comp.lang.basic.powerbasic)