Created
April 27, 2020 15:28
-
-
Save bitbonk/8378eaaefb5562f264896c8213805628 to your computer and use it in GitHub Desktop.
Task.WhenAll + AggregateExeption
This file contains 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
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
try | |
{ | |
await Task.WhenAll( | |
Task.Run(() => | |
{ | |
Console.WriteLine("begin one"); | |
throw new InvalidOperationException("one"); | |
}), | |
Task.Run(() => | |
{ | |
Console.WriteLine("begin two"); | |
throw new InvalidOperationException("two"); | |
})); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e); | |
} | |
} | |
} | |
/* Output of the above code in .NET Core 3.1 | |
begin one | |
begin two | |
System.InvalidOperationException: one | |
at ConsoleApp10.Program.<>c.<Main>b__0_0() in C:\Users\Ludewig\RiderProjects\ConsoleApp10\ConsoleApp10\Program.cs:line 18 | |
at System.Threading.Tasks.Task`1.InnerInvoke() | |
at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj) | |
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) | |
--- End of stack trace from previous location where exception was thrown --- | |
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) | |
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) | |
--- End of stack trace from previous location where exception was thrown --- | |
at ConsoleApp10.Program.Main(String[] args) in C:\Users\bitbonk\RiderProjects\ConsoleApp10\ConsoleApp10\Program.cs:line 14 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment