Skip to content

Instantly share code, notes, and snippets.

@mizrael
Created April 29, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizrael/bd0b0962226bf77c39b3c6a9d1eedb44 to your computer and use it in GitHub Desktop.
Save mizrael/bd0b0962226bf77c39b3c6a9d1eedb44 to your computer and use it in GitHub Desktop.
handling multiple exceptions from Task.WhenAll()
Task aggregationTask = null;
try{
var task1 = DoSomethingAsync();
var task2 = DoSomethingElseAsync();
aggregationTask = Task.WhenAll(task1, task2);
await aggregationTask;
}catch(Exception ex){
if(aggregationTask?.Exception?.InnerExceptions != null && aggregationTask.Exception.InnerExceptions.Any())
foreach (var innerEx in aggregationTask.Exception.InnerExceptions){
// do your magic here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment