As far as I know it is not defined (undefined behaviour) in C++STD how compiled application should handle situations when one shared library raises exception inside another one [shared lib]. The code produced by G++/Linux shows that it is possible to raise exceptions between shared libraries.
My questions are:
A
will not be able to handle an exception from shared library B
? [I mean the application would crash; library A
knows about possible exceptions from B
].That really depends on your use of shared libraries. If you use them as physical modules within a same application/system and compile them with the same compiler, you should be OK (as long as you also dynamically link to the C++ standard library).
However, if there is a possibility that a shared library is compiled with one compiler (including another version of the same compiler) and accessed by a module compiled by another one, you are in trouble: there is no standard binary compatibility interface for exceptions.
This seems to be a compiler-dependent issue. I have had problems with that on deploying to Windows, where the MinGW-GCC has to be built with a shared libstdc++ to enable cross-DLL exception handling (which is non-default for the Debian version and required me to re-compile the GCC).
Thus I assume there is no common ABI between compilers, since the GCC doesn't even conform with itself in all respects. With respect to technical considerations, the low-level exception handling information needs to be stored somewhere, and this somewhere is likely to be a third library C, which does handle exceptions. Compilers might be able to share this library, but I assume they aren't.
On the bright side: I am currently cross-compiling a fairly large project for POSIX systems and Windows and heavily using cross-library exceptions in a multi-threaded environment. It works with a shared libstdc++ for the GCC, and since all components are open source, I had the luxury to simply recompile all C++ dependencies for the MinGW.
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