Created
April 29, 2019 10:27
-
-
Save mizrael/bd0b0962226bf77c39b3c6a9d1eedb44 to your computer and use it in GitHub Desktop.
handling multiple exceptions from Task.WhenAll()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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