AggregateException 和 exception
AggregateException :只能捕获并行异常
Exception:可以捕获所有类型的异常
try
{
var task1 = Task.Run(() =>
{
throw new Exception("ex1");
});
Task.WaitAll(task1);
//throw new Exception("ex2");
}
catch (AggregateException ae)
{
//可捕获到 ex1
}
catch (Exception ex)
{
//因为ex1已经被AggregateException 捕获,所以这里捕获不到ex1,但可以捕获到ex2
}