开发者

Exception propagation across threads?

开发者 https://www.devze.com 2023-04-01 16:28 出处:网络
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.

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

精彩评论

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