When an exception is thrown, terminate is called, even though there is an appropriate handler, if there is any C code between the exception and the handler. This is a serious problem because a lot of third party software uses a C ABI and callbacks. (Note that this works with Sun CC.)
---------- main.cc ------------ #include <ostream> #include <iostream> #include <stdexcept> extern "C" { extern void enrollCallback( void (*pf)() ) ; extern void doCallback() ; } void f() { throw std::runtime_error( "Just a test" ) ; } extern "C" void callback() { f() ; } int main() { enrollCallback( &callback ) ; try { doCallback() ; } catch ( std::exception const& error ) { std::cout << "Exception caught: " << error.what() << std::endl ; } catch ( ... ) { std::cout << "Unknown exception caught" << std::endl ; } return 0 ; } ------------ test.c ----------- static void (*pf)() ; void enrollCallback( void (*cb)() ) { pf = cb ; } void doCallback() { (*pf)() ; } -------------- end sources ----------- Desired behavior: Program outputs: > Exception caught: Just a test when run. (This is the behavior of Sun CC.) Actual behavior: terminate is called. -- Summary: exception not caught when passing through C code Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: enhancement Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jkanze at cheuvreux dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: sparc-sun-solaris2.8 GCC host triplet: sparc-sun-solaris2.8 GCC target triplet: sparc-sun-solaris2.8 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19620