c++exception

try catch for an unknown exception


I'm using an old legacy library (C++03) compiled in Visual Studio 2003. When some physical hardware is available the library works, but throws an exception when the physical hardware is not available (such as on a development laptop):

try {
    // Legacy library that can throw an exception...
    LibraryCall();
}
catch (exception& ex) {
    int stdException = 0; // Thought it would hit this breakpoint...
}
catch (int) {
    int intException = 0; // ...also doesn't hit here...
}
catch (...) {
    int someOtherException = 0; // ...but the breakpoint does hit here
}

The exception is not hitting the std::exception catch as I expected. As noted in the comments and in this related question it may be possible to get additional information using std::current_exception.

Is there a way to get information on the exception in the "catch-all" ellipsis (...) section in pre-C++11?


Solution

  • This linked question provides an answer using std::exception_ptr, but requires both the legacy library and code using the library to be compiled with C++11 or later.

    As noted in comments from @Botje, @jabaa, and @WeijunZhou, you may be able to get information from the legacy library itself, or can guess the exception type using casting.

    Since the legacy library offers no clues and your guesses have not been successful, beyond a "general, unnamed exception", you are out of luck.

    Update: Also check out the answer from @MSalters which provides additional context.