I have the following code in Xamarin (tested in ios):
private static async Task<string> TaskWithException()
{
return await Task.Factory.StartNew (() => {
throw new Exception ("Booo!");
return "";
});
}
public static async Task<string> RunTask()
{
try
{
return await TaskWithException ();
}
catch(Exception ex)
{
Console.WriteLine (ex.ToString());
throw;
}
}
Invoking this as await RunTask()
, does throw the exception from the TaskWithException
method, but the catch method in RunTask
is never hit. Why is that? I would expect the catch to work just like in Microsoft's implementation of async/await. Am I missing something?