下面几篇文章阐述了,当Task在运行过程中发生了未处理异常时,在调用Task.Result, Task.Wait(), Task.WaitAll(), Task.WaitAny()时,都会抛出AggregateException异常。
下面的文章章节,阐述了如何在调用Task.Wait(),Task.WaitAll()和Task.WaitAny()方法时,捕获AggregateException异常:
Waiting for one or more tasks to complete
下面的文章阐述了TPL(Task Parallel Library)编程中的异常处理:
Exception handling (Task Parallel Library)
其中这里也提到了Task.Wait(), Task.WaitAll(), Task.WaitAny()方法会捕获AggregateException异常:
In such cases, the InnerExceptions property of the AggregateException exception that is caught at the Task.Wait, WaitAny, or WaitAll method contains one or more AggregateException instances, not the original exceptions that caused the fault.
下面的这篇文章也提到了,当Task在运行过程中发生了未处理异常,在Task.Result, Task.Wait(), Task.WaitAll(), Task.WaitAny()被调用时,会抛出AggregateException异常:
Parallel Programming Part 2: Waiting For Tasks and Exceptions Handling
When an exception occurs within a task (and is not caught), it is not thrown immediately. Instead, it is squirreled away by the .Net framework and thrown when some trigger member method is called, such as Task.Result, Task.Wait(), Task.WaitAll() or Task.WaitAny(). In this case, an instance of System.AggregateException is thrown that acts as a wrapper around one or more exceptions that have occurred. This is important for methods that coordinate multiple tasks like Task.WaitAll() and Task.WaitAny(), so the AggregateException is able to wrap all the exceptions within the running tasks that have occurred.