Skip to content

Instantly share code, notes, and snippets.

@BojanKomazec
Last active December 19, 2015 10:30
Show Gist options
  • Select an option

  • Save BojanKomazec/9e855ee46136afe576a5 to your computer and use it in GitHub Desktop.

Select an option

Save BojanKomazec/9e855ee46136afe576a5 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
public class Program
{
public static void Main()
{
Program.MainAsync().Wait();
}
private static async Task MainAsync()
{
var task = Task.Run(
() =>
{
throw new ArgumentNullException();
}
);
try
{
await task; // (1)
//task.Wait(); // (2)
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine($"Task.Status: {task.Status}");
Console.WriteLine($"Task.IsFaulted: {task.IsFaulted}");
Console.WriteLine($"Task.Exception: {((task.Exception == null) ? "null" : task.Exception.ToString())}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment