Skip to content

Instantly share code, notes, and snippets.

@bitbonk
Created April 27, 2020 15:28
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 bitbonk/8378eaaefb5562f264896c8213805628 to your computer and use it in GitHub Desktop.
Save bitbonk/8378eaaefb5562f264896c8213805628 to your computer and use it in GitHub Desktop.
Task.WhenAll + AggregateExeption
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