Exceptions and C-callbacks?

Mike Stump mrs@windriver.com
Wed Feb 9 14:05:00 GMT 2000


> Date: Tue, 08 Feb 2000 22:48:21 -0800
> From: "Rob Kramer" <wrobbie@my-Deja.com>

> My application uses a function from a C-library (an event handler)
> that does a callback to a static function in my application class
> which in turn calls some C++ code (via a stored 'this' pointer).

>   Application -> C-event handler -> C-callback -> C++ callback handler.

> My problem: the C++ callback handler can throw exceptions, but they
> are never caught in the application and result in an 'Abort!'.

You must compile all code with -fexceptions on, the default for C is
off as I recall.  Do this, and it should work.  If it doesn't, make
sure your compiler is new enough.  If you need to throw through code
that isn't compiled by gcc and -fexceptions, then, the only way to
make it work (besides switching over to explicit setjmp/longjmp from a
catch (...) in the C++ callback handler to the C-event handler and
then rethrowing from there) is to turn on -fsjlj-exceptions in your
system and recompile.


More information about the Gcc mailing list