When is it OK to throw an exception from a destructor in C++?

后端 未结 7 1260
独厮守ぢ
独厮守ぢ 2020-12-16 23:33

I know the rule is to NEVER throw one during a destructor, and I understand why. I would not dare do it. But even the C++ Faq Lite says that this rule is good 99% of the tim

7条回答
  •  温柔的废话
    2020-12-17 00:19

    You can throw an exception from a destructor if this destructor is not called automatically during stack unwinding, or throwing the exception will result in a call of terminate(). To determine if it is safe to throw exceptions from a destructor, use standard function uncaught_exception(); if it returns false, it is safe to throw an exception

提交回复
热议问题