Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Throwing C++ exceptions outside static library?

As a rule, exceptions must not propagate module boundaries as for example explained in Herb Sutters C++ Coding Standards (item 62). When compiled with different compilers or just compiler settings this might crash.

I can understand the issue in case e.g. of dynamic link libraries. But I wonder whether it also holds for static libraries. Is a static library a module in the sense of the above rule? If the library is compiled with other compiler settings (e.g. alignment) might the program crash, if an exception is thrown out of the static library and caught in the application?

like image 549
Kit Fisto Avatar asked Dec 21 '12 13:12

Kit Fisto


1 Answers

Herb Sutters' description is also suitable for static library:

There is no ubiquitous binary standard for C++ exception handling. Don't allow exceptions to propagate between two pieces of code unless you control the compiler and compiler options used to build both sides; otherwise, the modules might not support compatible implementations for exception propagation. Typically, this boils down to: Don't let exceptions propagate across module/subsystem boundaries.

like image 182
billz Avatar answered Oct 21 '22 15:10

billz