title: C# async / await unobserved exception
body: <p>I'm trying to understand why the following code:</p>
  
  <pre><code>async void Handle_Clicked(object sender, System.EventArgs e)
  {
      try
      {
          await CrashAsync("aaa");
      }
      catch (Exception exception)
      {
          Log($"observed exception");
  
          Log($"Exception: {exception.Message}");
      }
  }
  
  private async Task CrashAsync(string title)
  {
      Log($"CrashAsync ({title}) - before");
  
      await Task.Delay(1000);
  
      throw new Exception($"CrashAsync ({title})");
  
      Log($"CrashAsync ({title}) - after");
  }
  </code></pre>
  
  <p>produces the expected result:</p>
  
  <blockquote>
    <p>thread #1: CrashAsync (aaa) - before</p>
    
    <p>thread #1: observed exception</p>
    
    <p>thread #1: Exception: CrashAsync (aaa)</p>
  </blockquote>
  
  <p>but if I change it to this one:</p>
  
  <pre><code>async void Handle_Clicked(object sender, System.EventArgs e)
  {
      try
      {
          await CrashAsync("aaa").ContinueWith(async (t) =&gt;
          {                   
              await CrashAsync("bbb");
          },TaskContinuationOptions.OnlyOnRanToCompletion);
      }
      catch (Exception exception)
      {
          Log($"observed exception");
  
          Log($"Exception: {exception.Message}");
      }
  }
  </code></pre>
  
  <p>I get the following output:</p>
  
  <blockquote>
    <p>thread #1: CrashAsync (aaa) - before</p>
    
    <p>thread #1: observed exception</p>
    
    <p>thread #1: Exception: A task was canceled.</p>
    
    <p>thread #2: unobserved exception</p>
    
    <p>thread #2: System.Exception: CrashAsync (aaa)
      at AsyncTest.AsyncTestPage+c__async3.MoveNext () [0x000ad] in /Users/johndoe/Development/Xamarin/AsyncTest/AsyncTest/AsyncTestPage.xaml.cs:82 </p>
  </blockquote>
  
  <p>where:</p>
  
  <pre><code>TaskScheduler.UnobservedTaskException += (sender, e) =&gt;
  {
      Debug.WriteLine($"thread #{Environment.CurrentManagedThreadId}: unobserved exception");
  
      foreach (var exception in e.Exception.Flatten().InnerExceptions)
      {
          Debug.WriteLine($"thread #{Environment.CurrentManagedThreadId}: {exception}");
      }
  };
  </code></pre>
  
  <p>The continuation condition is not satisfied so the ContinueWith task is cancelled, but why do I have unobserved exception?</p>