首页 > Windows开发 > 详细

C# aggregateexception flatten innerexceptions

时间:2020-01-20 00:48:14      阅读:125      评论:0      收藏:0      [点我收藏+]
static void AggregateExceptionsDemo()
        {
            var task1 = Task.Factory.StartNew(() =>
              {
                  var child1 = Task.Factory.StartNew(() =>
                  {
                      throw new CustomException("Attached child2 faulted.");

                  },TaskCreationOptions.AttachedToParent);
                  throw new CustomException("Attached child1 faulted.");
              },TaskCreationOptions.AttachedToParent);

            try
            {
                task1.Wait();
            }
            catch(AggregateException aes)
            {
                foreach(var e in aes.Flatten().InnerExceptions)
                {
                    if(e is CustomException)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
        }

C# aggregateexception flatten innerexceptions

原文:https://www.cnblogs.com/Fred1987/p/12216028.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!