Reading book a concurrency C# which says when Task.WhenAll is awaited, only one exception is trhown if multiple exceptions are thrown from each task in Task.WhenAll
Bit confised as Ive seen sample code below which suggests all exceptions are captured in the AggregateException and not just ONE thrown?
Task allTasks = Task.WhenAll(task1, task2);
try
{
await allTasks;
}
catch
{
AggregateException allExceptions = allTasks.Exception;
...
}
whereas the below only expects one exception to be thrown
Well the code below says it will only throw one of the excpetions from the book which is confusing
var task1 = ThrowNotImplementedExceptionAsync();
var task2 = ThrowInvalidOperationExceptionAsync();
try
{
await Task.WhenAll(task1, task2);
}
catch (Exception ex)
{
// "ex" is either NotImplementedException or InvalidOperationException.
...
}