Skip to content

Instantly share code, notes, and snippets.

@usausa
Last active April 2, 2020 06:52
Show Gist options
  • Select an option

  • Save usausa/f6be9a2d31bca60f3ad778e6175b0509 to your computer and use it in GitHub Desktop.

Select an option

Save usausa/f6be9a2d31bca60f3ad778e6175b0509 to your computer and use it in GitHub Desktop.
class Program
{
static async Task Main(string[] args)
{
try
{
await Task.Run(async () => await LongProcessAsync());
}
catch (Exception e)
{
// Can catch
Console.WriteLine(e);
}
try
{
await Task.Run(LongProcessAsync);
}
catch (Exception e)
{
// Can't catch
Console.WriteLine(e);
}
}
private static async ValueTask LongProcessAsync()
{
// Context switch
await Task.Delay(100);
throw new Exception("Otanko🍆");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment