当一个异常在多线程C ++ 11程序中未处理时会发生什么? [英] What happens when an exception goes unhandled in a multithreaded C++11 program?

查看:274
本文介绍了当一个异常在多线程C ++ 11程序中未处理时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个C ++ 11程序运行两个线程,其中一个抛出一个未处理的异常,会发生什么?整个程序会死亡吗?将异常抛出的线程单独死亡(如果是这样,我可以获得这种情况下的异常)?

If I have a C++11 program running two threads, and one of them throws an unhandled exception, what happens? Will the entire program die a fiery death? Will the thread where the exception is thrown die alone (and if so, can I obtain the exception in this case)? Something else entirely?

推荐答案

没有什么真的改变了。 n3290中的措辞是:

Nothing has really changed. The wording in n3290 is:


如果没有找到匹配的处理程序,函数 std :: terminate / code>被调用

If no matching handler is found, the function std::terminate() is called

terminate 的行为可以用 set_terminate 定制,但

The behavior of terminate can be customized with set_terminate, but:


Required behavior: A terminate_handler shall terminate execution of the program without returning to the caller.

这篇关于当一个异常在多线程C ++ 11程序中未处理时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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