MSDN原文:
任务基础结构会将内部异常包装在 AggregateException 实例中。 AggregateException 具有一个 InnerExceptions 属性,可枚举该属性来检查引发的所有原始异常,并单独处理(或不处理)每个异常。 即使只引发了一个异常,也仍会将该异常包装在 AggregateException 中。

简单处理内部异常的例子
 

C# code
 
    
var task1 = Task.Factory.StartNew(() => { throw new Exception( " I'm bad, but not too bad! " ); }); try { task1.Wait(); } catch (AggregateException ae) { foreach ( var a in ae.InnerExceptions) { Console.WriteLine(task1.IsFaulted); // 这里将输出True,表示task1任务失败了 Console.WriteLine(a.Message); } } Console.Read();



输出:
True
I'm bad, but not too bad!


当运行到throw new Exception("I'm bad, but not too bad!");的时候,VS会在这行中断运行,并显示错误消息,这是没关系的,按F5继续查看后续操作。

MSDN原文:
当启用“仅我的代码”时,在某些情况下,Visual Studio 将在引发异常的行上中断运行,并显示错误消息“异常未由用户代码处理”。此错误是良性的。 按 F5 继续并查看在这些示例中演示的异常处理行为。 若要阻止 Visual Studio 在出现第一个错误时中断运行,只需在“工具”->“选项”->“调试”->“常规”下取消选中“仅我的代码”复选框即可。