When an exception exits a function in a DLL the mingw32 runtime simply calls terminate std::unexpected instead of propagating the exception to the code that is calling the DLL. What solutions are there to this problem? The DLL and the application calling it are both compiled with the same compiler.
There are two different exception mechanisms supported by mingw32: SJLJ and Dwarf2. Should one of them work better than the other for this? Perhaps the only option is to switch to MSVC or ICC or maybe changing build options alone would help?
Notice that not even catch(...) will catch any exception, not even built-in types (throw 1;), so it is not about the visibility of the exception type.
When an exception is cached in a catch block, you can re-throw it using the throw keyword (which is used to throw the exception objects). Or, wrap it within a new exception and throw it.
Answer: When an exception is thrown in the catch block, then the program will stop the execution.
Try-catch block is used to handle the exception. In a try block, we write the code which may throw an exception and in catch block we write code to handle that exception. Throw keyword is used to explicitly throw an exception. Generally, throw keyword is used to throw user defined exceptions.
throws: The throws keyword is used for exception handling without try & catch block. It specifies the exceptions that a method can throw to the caller and does not handle itself.
Is the runtime assuming that extern "C"
functions will never throw exceptions? I'm not familiar with MinGW but I know that Visual Studio has a bunch of command line arguments to control this sort of behavior. For example, the /EHs
option will cause it to assume that extern "C"
will never throw and it will treat functions that do throw by calling std::unexpected()
which in turn calls std::terminate()
. You might want to call std::set_unexpected()
to establish an unexpected exception handler and see if it traps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With