views:

593

answers:

1

I am trying to load a dynamic library using dlopen function. This library contains a static object, which throws an exception in its constructor. I have a "try-catch(...)" block around the dlopen call, but it doesn't catch the exception, and I just see "Abort" printed.

How am I able to catch this exception?

+4  A: 

Short Answer: You Can't

Thinking about it again.
The original statements holds, but you must also remember that dlopen() is a C library function. C does not support exceptions. Thus throwing an exception that crosses from C++ code to C ( Your global object back upto dlopen() ) code will also cause application termination.

See here:http://stackoverflow.com/questions/222175/why-destructor-is-not-called-on-exception#222358

These are the situations under which throwing an exception will terminate the application. Your specific situation is covered by:

An exception escapes the constructor/destructor of a non local static (ie global)

Martin York