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

本站最新发布   C#从入门到精通
试听地址  
https://www.xin3721.com/eschool/CSharpxin3721/

复制代码
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);
                    }
                }
            }
        }
复制代码
相关教程