Topic: Getting uncaught exception


Author: Venkat Chandra <venkat@workgroup.com>
Date: 1997/11/05
Raw View
Greetings,

I have my function installed for set_terminate.
I have the following code.

main()
{
    set_terminate(my_terminate);
    ...
}

my_terminate()
{
    printf("I want to be able to print the uncaught exception somehow");

    abort();
}

I want to be able to print whatever possible about the uncaught
exception.
Is this possible at all ?
If so how ?

Regards,

--
---------------------------------------------------------------------
Venkat Chandra

Workgroup Technology Corporation,      "Think Timing, Think CMS"
91, Hartwell Ave,                      Web : http://www.workgroup.com/
Lexington,                             Phone : (781) 674 7612.
MA 02173.                              Fax : (781) 674 0034.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Date: 1997/11/07
Raw View
Venkat Chandra wrote:
>
> I have my function installed for set_terminate.
> I want to be able to print whatever possible about the uncaught
> exception.
> Is this possible at all ?
> If so how ?

The only way to find out about an unknown exception is to
rethrow it and try to catch it with specific exception handlers:

 try { throw; }
 catch (foo& x) { ... }
 catch (bar& x) { ... }
 catch (...) { ... }

However, this only works if the exception hasn't yet been
handled. The latest public draft standard doesn't specify
whether or not an exception is considered "handled" on entry to
the terminate function. But section 15.3 para 9 says:

"If no matching handler is found in a program, the function
terminate() is called. Whether or not the stack is unwound
before calling terminate() is implementation-defined."

This implies to me that they want to specify as little as
possible about this case, and that therefore the above might
very well not work inside a terminate handler.

Instead, you'll have to wrap main() in a try block, and do the
above. This, of course, won't handle exceptions occurring before
and after main (in the constructors and destructors of static
objects), but exceptions occurring then should be considered
bugs and found with a debugger.

--

Ciao,
Paul
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]