Throwing C++ exceptions outside static library?

前端 未结 3 541
面向向阳花
面向向阳花 2021-01-04 14:06

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

3条回答
  •  忘掉有多难
    2021-01-04 14:34

    Generally, a static library has to be compiled by the same compiler and the same compiler settings (mostly) to be compatible with the deliverable (a dynamic library or an executable).

    You can, then, throw exceptions outside the boundaries of a static library because it's not much different than a set of .obj files your compiler generated. And you obviously can throw exceptions between different .obj modules.

    EDIT:

    To sum up the comments:

    1. You can only use a static library if you're using the same compiler and compiler settings used to compile the library.
    2. You can throw exceptions between modules compiled with the same compiler and compiler settings.
    3. From 1) and 2) follows that you can throw exceptions from a static library because, if you're using it, that means you're using the same compiler and compiler settings, hence you can throw exceptions.

提交回复
热议问题