When throwing a custom exception from a Task.Run(...).Result, the catch block finds an AggregateException instead of the CustomException. Why?
public MainPage()
{
this.InitializeComponent();
CallAMethod();
}
static bool AMethod()
{
return Task.Run(() =>
{
throw new CustomException();
return false;
}).Result;
}
static bool CallAMethod()
{
try
{
return AMethod();
}
catch (CustomException e)
{
//not caught
throw;
}
catch (Exception ex)
{
//caught?
throw;
}
}
Here is the custom Exception class
class CustomException : Exception
{
}