Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 334
Matthieu M. Avatar asked Sep 01 '11 15:09

Matthieu M.


1 Answers

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.

like image 57
Howard Hinnant Avatar answered Oct 20 '22 21:10

Howard Hinnant