我应该这样做吗?
int x = 0;
Task<int> calc = Task.Factory.StartNew (() => 7 / x);
try
{
Console.WriteLine (calc.Result);
}
catch (AggregateException aex)
{
Console.Write (aex.InnerException.Message); // Attempted to divide by 0
}
或这个?
int x = 0;
try
{
Task<int> calc = Task.Factory.StartNew (() => 7 / x);
Console.WriteLine (calc.Result);
}
catch (AggregateException aex)
{
Console.Write (aex.InnerException.Message); // Attempted to divide by 0
}
如果任务立即开始并且在我们进入 try catch 块之前,我们将不会捕获它......!?