I am following the pattern specified here by Microsoft. https://msdn.microsoft.com/en-us/library/hh191443.aspx
The article walks through developing async code using await. However, they do not talk about what happens when there is an exception before the await returns.
In the example below the outside exception ends the parent thread and the task has no thread to come back to. How do I handle this scneario?
class Program
{
private static void Main(string[] args)
{
CallAsync();
Console.ReadKey();
}
public static async void CallAsync()
{
var task = CallExceptionAsync();
ThrowException("Outside");
await task;
}
public static Task CallExceptionAsync()
{
return Task.Run(() =>
{
ThrowException("Inside");
});
}
public static void ThrowException(string msg)
{
throw new Exception(msg);
}
}