title: Handling multiple exceptions from async parallel tasks
body: <p><strong>Problem</strong></p>
  
  <p>Several tasks are run in parallel, and all, none, or any of them might throw exceptions. When all the tasks have finalized, all the exceptions that might have happened must be reported (via log, email, console output.... whatever).</p>
  
  <p><strong>Expected behavior</strong></p>
  
  <p>I can build all the tasks via linq with async lambdas, and then await for them running in parallel with <code>Task.WhenAll(tasks)</code>. Then I can catch an <code>AggregateException</code> and report each of the individual inner exceptions.</p>
  
  <p><strong>Actual behavior</strong></p>
  
  <p>An <code>AggregateException</code> is thrown, but it contains just one inner exception, whatever number of individual exceptions have been thrown.</p>
  
  <p><strong>Minimal complete verifiable example</strong></p>
  
  <pre><code>static void Main(string[] args)
  {
      try
      {
          ThrowSeveralExceptionsAsync(5).Wait();
      }
      catch (AggregateException ex)
      {
          ex.Handle(innerEx =&gt;
          {
              Console.WriteLine($"\"{innerEx.Message}\" was thrown");
              return true;
          });
      }
  
      Console.ReadLine();
  }
  
  private static async Task ThrowSeveralExceptionsAsync(int nExceptions)
  {
      var tasks = Enumerable.Range(0, nExceptions)
          .Select(async n =&gt;
          {
              await ThrowAsync(new Exception($"Exception #{n}"));
          });
  
      await Task.WhenAll(tasks);
  }
  
  private static async Task ThrowAsync(Exception ex)
  {
      await Task.Run(() =&gt; {
          Console.WriteLine($"I am going to throw \"{ex.Message}\"");
          throw ex;
      });
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <p>Note that the output order of the "I am going to throw" messages might change, due to race conditions.</p>
  
  <pre><code>I am going to throw "Exception #0"
  I am going to throw "Exception #1"
  I am going to throw "Exception #2"
  I am going to throw "Exception #3"
  I am going to throw "Exception #4"
  "Exception #0" was thrown
  </code></pre>