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

}

posted on 2021-01-13 11:51  gfbppy  阅读(246)  评论(0编辑  收藏  举报

导航