Question

This is somewhat similar to "Disabling C++ exceptions, how can I make any std:: throw() immediately terminate?." I would like my program to terminate whenever an exception is thrown out of the STL.

The problem is as follows: I am writing a library which is then loaded as a shared object and executed by a program I don't have control over. Unfortunately this program runs everything in a big try bock so that I don't get a stack trace/core dump if an error is thrown, rendering the ::at class of function's out of range error useless.

This sounds like the ideal use case for -fno-exceptions, but I can't just use -fno-exceptions, because boost_log and the program that calls me both have exception handling defined in their headers giving me compile errors with -fno-exceptions.

Is there a way to enable -fno-exceptions only for stl exceptions?

Was it helpful?

Solution

With C++11, the easiest way to do is to add noexcept to the signature of the top level function that is called from your shared library:

void called_func() noexcept;

This will cause any unhandled exceptions in the called_func stack frame (or below if they are not handled) to terminate the execution of the program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top