title: How do I globally handle exceptions across all threads?
body: <p>It seems an unhandled exception will crash the program only if it's in the UI thread. Exceptions in other threads fail silently. I want to be able to either exit the application or display info about the exception when exceptions are thrown in these threads. Unfortunately the <code>UnhandledException</code> event only seems to work for one thread.</p>
  
  <pre><code>private void Window_Loaded(object sender, RoutedEventArgs e)
  {
      AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  
      Task.Run(() =&gt; throw new Exception("This is an exception."));
  }
  
  private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  {
      MessageBox.Show(e.ExceptionObject.ToString());
  }
  </code></pre>
  
  <p>This neither crashes the application nor notifies me of the exception. Is there a way to make sure exceptions across all threads never cause silent failures, either using code or with some kind of application setting?</p>
  
  <p><a href="https://stackoverflow.com/questions/12980712/what-is-the-best-way-to-catch-exception-in-task">What is the best way to catch exception in Task?</a> does not address using global exception handling to prevent silent failures, and so it is very different from my question.</p>