std :: terminate()触发堆栈放松吗?
我一直在尝试实现 Exception 类,对于程序终止,我决定使用 std::terminate() ,但无论是否使用,我都不会使用std::terminate()
触发堆栈展开过程。
例如,如果我编译并运行此代码:
struct Test {
Test() {
std::cout << "Constructed\n";
}
~Test() {
std::cout << "Destructed\n";
}
};
int main() {
Test t;
std::terminate();
return 0;
}
它将输出:
Constructed
terminate called without an active exception
并且似乎析构函数没有被调用。
I've been trying to implement Exception
class, and for program termination i've decided to use std::terminate()
, but i'm not suse whether or not std::terminate()
triggers stack unwinding process.
For example, if i compile and run this code:
struct Test {
Test() {
std::cout << "Constructed\n";
}
~Test() {
std::cout << "Destructed\n";
}
};
int main() {
Test t;
std::terminate();
return 0;
}
it will output this:
Constructed
terminate called without an active exception
and it seems that destructor is not being called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
std::terminate()
的标准处理程序直接调用std::abort
。如果您查看此处,您会发现
std::abort()
没有调用任何析构函数。The standard handler for
std::terminate()
calls directlystd::abort
.If you take a look here, you will find out that
std::abort()
did not call any of the destructors.