public class Program
{
public static T TakeFunc<T>(Func<T> func){
try{
var x = func();
Console.WriteLine("Success");
return x;
}
catch(Exception ex){
Console.WriteLine("ex caught");
return default(T);
}
finally{
Console.WriteLine("finally");
}
}
public static void Main(string[] args)
{
TakeFunc(async () => await test());
}
private async static Task<List<string>> test(){
await Task.Delay(1000);
List<string> a = null;
a.Add("sdff");
return a;
}
}
The output of this is:
Success
finally
Why isn't the ex caught even though the test method is under an await? I've read that await usually catches the error. Does this have something to do with the delegate being asynchronous?