VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C# aggregateexception flatten innerexceptions

复制代码
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);
                    }
                }
            }
        }
复制代码

相关教程