Exceptions and threads

Started by
2 comments, last by SiCrane 15 years, 3 months ago
If a thread throws an exception it doesn't catch, will any other thread be affected? Are there any differences between thread libraries regarding this? I'll be using either boost::thread or SDL to create threads.
Advertisement
Typically unhandled exceptions cause the process to be brought down. Either by the OS or by language runtime code, depending on exactly what you mean by "exception", the conventions of the language in question, and how exception handling is implemented.
-Mike
Threads are nothing more than processor time that is assigned to a certain task. Threads that belong to one process all share the same memory context (basically, except for TLS). So, yes, if one thread throws an exception that is not handled, it will kill your application.

Quote:Are there any differences between thread libraries regarding this? I'll be using either boost::thread or SDL to create threads.


No, those libraries just abstract the threading functions provided by the OS. Infact its not possible to implement real multithreading without using system calls, as threading must be handled by the OS.
It's actually platform dependent what occurs. Typically an unhandled C++ exception in a thread will bring down the entire process. However, this behavior can be altered, depending on the platform. For example, on Windows with MSVC, if the process is being debugged an unhandled exception may not appear to do anything other than terminate the thread the exception occurred in. Even when not debugged, with a debug build a program with an unhandled exception in MSVC will generally bring up a dialog with the classic "Abort, Retry, Ignore" options. While this dialog is displayed, all other threads will happily continue executing until such time that you actually hit the abort button.

This topic is closed to new replies.

Advertisement