Throwing C++ exceptions across DLL boundaries

前端 未结 2 1808
庸人自扰
庸人自扰 2020-12-05 13:35

I\'ve read various things about how one should not allocate heap memory in one DLL and deallocate it from outside that DLL. But what about throwing an exception object that

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 13:56

    Throwing C++ exceptions across DLL boundaries is only possible when all modules use the same C++ runtime, in which case they share a heap as well. But this can be a maintenance burden, especially when libraries from multiple vendors are involved, so it is discouraged.

    If you want error-handling which is portable across multiple compilers/compiler versions/compiler settings, either use return codes or OS-provided exceptions (e.g. SEH on Windows)/

提交回复
热议问题