Monthly Read Posts in Apr 2019
Programming Languages
C++ 11之后的 destructor 默认是 noexcept
,如果有 active exception 逃逸出 dtor 会直接触发 std::terminate()
,即使外部有 catch handler。可以用 noexcept(false)
显式关闭。
因为 stack unwinding 是可以嵌套的,一个精心设计的场合下(见文中例子),可以做到多个 active exception 不在一个层次里,因此也不会触发 double-exception situation。
an exception leaves out from main function
an exception leaves out from initial function of a thread
an exception leaves out from dtor (since c++ 11 with noexcept guarantee)