title: Where does an async Task throw Exception if it is not awaited?
body: <p>I have the following example: (please also read comments in code, as it will make more sense ) </p>
  
  <pre><code>public async Task&lt;Task&lt;Result&gt;&gt; MyAsyncMethod() 
  {
      Task&lt;Result&gt; resultTask = await _mySender.PostAsync();
      return resultTask; 
  
      // in real-life case this returns to a different assembly which I can't change
     // but I need to do some exception handling on the Result in here
  }
  </code></pre>
  
  <p>let's assume the <code>PostAsync</code> method of _<code>mySender</code>  looks like this: </p>
  
  <pre><code>public Task&lt;Task&lt;Result&gt;&gt; PostAsync() 
  {
    Task&lt;Result&gt; result = GetSomeTask(); 
    return result;
  }
  </code></pre>
  
  <p>The question is: </p>
  
  <p>As I don't await for the actual <code>Result</code> in the <code>MyAsyncMethod</code> and if <code>PostAsync</code> method throws an exception, in which context is the exception going to be thrown and handled?</p>
  
  <p>and </p>
  
  <p>Is there any way I can handle exceptions in my assembly? </p>
  
  <p>I was surprised that when I tried to change <code>MyAsyncMethod</code> to: </p>
  
  <pre><code> public async Task&lt;Task&lt;Result&gt;&gt; MyAsyncMethod() 
  {
    try 
    {
      Task&lt;Result&gt; resultTask = await _mySender.PostAsync();
      return resultTask; 
    }
    catch (MyCustomException ex) 
    {
    } 
  }
  </code></pre>
  
  <p>the exception was caught here, event if there's no await for the actual result. It happens that the result of <code>PostAsync</code> is already available and the exception is thrown in this context right?? </p>
  
  <p>Is it possible to use <code>ContinueWith</code> to handle exceptions in the current class? For example: </p>
  
  <pre><code>public async Task&lt;Task&lt;Result&gt;&gt; MyAsyncMethod() 
  {
      Task&lt;Result&gt; resultTask = await _mySender.PostAsync();
      var exceptionHandlingTask = resultTask.ContinueWith(t =&gt; { handle(t.Exception)}, TaskContinuationOptions.OnlyOnFaulted);
      return resultTask;
  }
  </code></pre>