title: Unhandled Exceptions thrown in threads are not caught
body: <p>I'm working on a project that is implemented using plain <code>threads</code>. Most of the expected exceptions in the application are handled, however, there are cases where one of the threads throws an unexpected exception and the application just crashes (the application is both <code>I/O</code> and <code>Client-Server</code> based so it's practically impossible to handle all the exceptions). </p>
  
  <p>To fix this, I'm trying to define a global <code>UnhandledExceptionHandler</code> so that the application displays a friendly message instead of crashing. This is what I tried:</p>
  
  <pre><code>public partial class App : Application
  {
      private void Application_Startup(object sender, StartupEventArgs e)
      {
          AppDomain.CurrentDomain.UnhandledException +=
              new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  
          // The rest of the startup logic goes here
      }
  
      void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
      {
          Utilities.DisplayUnhandledException((Exception)e.ExceptionObject);
      }
  }
  </code></pre>
  
  <p>This doesn't work though. The <code>CurrentDomain_UnhandledException</code> is never called. Unfortunately, I can't change the structure of the application, which means I can't use the Task Parallel Library. I can't figure out why this doesn't work. Is there any other way to handle exceptions thrown in threads? Any help is appreciated.</p>