Skip to content

Instantly share code, notes, and snippets.

@anton-putau
Last active March 11, 2016 12:38
Show Gist options
  • Save anton-putau/416cb5b03649f38edc5a to your computer and use it in GitHub Desktop.
Save anton-putau/416cb5b03649f38edc5a to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
namespace TestException
{
class Program
{
static void Main(string[] args)
{
var p = new Program();
p.AsyncMain().Wait();
Console.ReadKey();
}
public async Task Run()
{
try
{
await SomeJob2();
}
catch (Exception e)
{
Console.WriteLine($"{e.GetType()}");
}
}
public async Task SomeJob()
{
throw new Exception();
}
public Task SomeJob2()
{
try
{
return SomeJob();
}
catch (Exception e)
{
throw new AggregateException(e);
}
}
public async Task AsyncMain()
{
await Run();
}
}
}
@anton-putau
Copy link
Author

So, output will be 'exception'. If we wait for async task in SomeJob2 it will be 'aggregateexception'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment