What happens when an exception goes unhandled in a multithreaded C++11 program?

R. Martinho Fernandes picture R. Martinho Fernandes · Sep 1, 2011 · Viewed 15.1k times · Source

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?

Answer

Ben Voigt picture Ben Voigt · Sep 1, 2011

Nothing has really changed. The wording in n3290 is:

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

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.

So the program exits in such a case, other threads cannot continue running.