开发者

Exception propagation across threads?

In relation with This question.

C++11 adds the ability to marshall an exception to a different threads (using std::exception_ptr) and resumes its propagation.

I was wondering if such a propagation was automatic, that is: if I fail to handle an exception in a thread, is it automatically propagated in the parent thread ?

I somewhat doubt it (or it would have to wait explicitly for the join开发者_如何学Python in some way), but I am not savvy on C++11 yet. Notably, I think that in the case of a std::future, it could store the exception automatically.


Propagation is not automatic with thread. If a thread throws, and that exception is not caught, the program terminates no matter what.

future and shared_future will store an uncaught exception in the child thread. That exception is then automatically propagated when get is called.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜