title: Unhandled exception handler not called for Metro / WinRT UI async void event handler
body: <p>Consider the following to be extracts from a Windows 8 Metro / WinRT app, which have been reduced to the bare minimum required to show the anomaly:</p>
  
  <pre><code>public class App : Application
  {
      public App()
      {
          UnhandledException += (sender, e) =&gt; e.Handled = true;
      }
  }
  
  public class MainPage : Page
  {
      private void Button_Click_1(object sender, RoutedEventArgs e)
      {
          throw new NotSupportedException();
      }
  
      private async void Button_Click_2(object sender, RoutedEventArgs e)
      {
          throw new NotSupportedException();
      }
  }
  </code></pre>
  
  <p>So given a Metro UI with two buttons and their click event handlers, the only difference is that the second event handler is marked as <code>async</code>.</p>
  
  <p>Then clicking on each button, I would expect the UnhandledException handler to be called in <strong>both</strong> cases, since they (should) both be entered via the UI thread and associated synchronization context. 
  My understanding is that, for <code>async void</code> methods, any exceptions should be captured and 'rethrown' (preserving the original stacktrace) via the initial synchronization context, which is also clearly stated in the <a href="http://blogs.msdn.com/b/pfxteam/archive/2012/04/12/10293335.aspx" rel="noreferrer">Async / Await FAQ</a>.</p>
  
  <p>But the UnhandledException handler is <strong>not</strong> called in the <code>async</code> case, so the application crashes! Since this challenges what I consider an otherwise very intuitive model, I need to know why! Yes, I know I could wrap the body of the handler in a <code>try { } catch { }</code>, but my question is why isn't the backstop UnhandledException handler called?</p>
  
  <p>To further emphasise why this doesn't make sense, consider the following practically identical extracts from a WPF app also using async / await and targeting .NET Framework 4.5:</p>
  
  <pre><code>public class App : Application
  {
      public App()
      {
          DispatcherUnhandledException += (sender, e) =&gt; e.Handled = true;
      }
  }
  
  public class MainWindow : Window
  {
      private void Button_Click_1(object sender, RoutedEventArgs e)
      {
          throw new NotSupportedException();
      }
  
      private async void Button_Click_2(object sender, RoutedEventArgs e)
      {
          throw new NotSupportedException();
      }
  }
  </code></pre>
  
  <p>[There is a subtle difference that WPF has both an Application DispatcherUnhandledException event handler as well as an AppDomain UnhandledException event handler, but you can only mark the exception as 'handled' in the DispatcherUnhandledException, which aligns with the Metro / WinRT Application UnhandledException event handler above.]</p>
  
  <p>Then clicking on each button, the DispatcherUnhandledException handler is indeed called in <strong>both</strong> cases, as expected, and the application does <strong>not</strong> crash.</p>