Task.Result, Task.Wait(), Task.WaitAll(), Task.WaitAny()都会抛出AggregateException异常(链接)

下面的文章章节,阐述了如何在调用 Task.Wait(), Task.WaitAll()Task.WaitAny()方法时,捕获 AggregateException异常:

下面的文章阐述了 TPL(Task Parallel Library)编程中的异常处理:

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异常:

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.

Original: https://www.cnblogs.com/OpenCoder/p/14715756.html
Author: PowerCoder
Title: Task.Result, Task.Wait(), Task.WaitAll(), Task.WaitAny()都会抛出AggregateException异常(链接)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/552878/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球