using System.Threading.Tasks;
using System.Collections.Generic;
public static async void Main()
Console.WriteLine("Hello World");
TestTaskWhenAllException("only 1 that throws", Throws());
TestTaskWhenAllException("only 1 that no throws", NoThrows());
TestTaskWhenAllException("2 tasks, 1 that throws", Throws(), NoThrows());
TestTaskWhenAllException("2 tasks, the other that throws", NoThrows(), Throws());
TestTaskWhenAllException("2 tasks that throw", Throws(), Throws());
TestTaskWhenAllException("2 tasks that no throw", NoThrows(), NoThrows());
private static async void TestTaskWhenAllException(string name, params Task[] tasks) {
Console.WriteLine("Testing " + name);
Task task = Task.WhenAll(tasks);
Console.WriteLine("\t - Thrown exception is "+e.GetType().ToString()+": "+e.Message);
Console.WriteLine("\t - Task exception is "+task.Exception.GetType().ToString() + " (with " + task.Exception.InnerExceptions.Count + " inner): "+task.Exception.Message);
Console.WriteLine("\t - Are they equal? "+(e == task.Exception).ToString());
private static async Task Throws() {
throw new ApplicationException("I miss the office grapes");
private static async Task NoThrows() {