これを行う必要がありますか?
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 ブロックに入る前に、それをキャッチしません...!?