中止,终止或退出? [英] abort, terminate or exit?

查看:144
本文介绍了中止,终止或退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

推荐答案

我的建议是不要使用任何一个。相反,捕获你不能在main()中处理的异常,只是从那里返回。这意味着您可以确保堆展开正确发生,并调用所有析构函数。换句话说:

My advice would be not to use any of them. Instead, catch the exceptions you can't handle in main() and simply return from there. This means that you are guaranteed that stack unwinding happens correctly and all destructors are called. In other words:

int main() {
    try {
       // your stuff
    }
    catch( ... ) {
       return -1;    // or whatever
    }
}

这篇关于中止,终止或退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆