Task.Exception Task.Exception Task.Exception Task.Exception Property

定义

获取导致 AggregateException 提前结束的 TaskGets the AggregateException that caused the Task to end prematurely. 如果 Task 成功完成或尚未引发任何异常,这将返回 nullIf the Task completed successfully or has not yet thrown any exceptions, this will return null.

public:
 property AggregateException ^ Exception { AggregateException ^ get(); };
public AggregateException Exception { get; }
member this.Exception : AggregateException
Public ReadOnly Property Exception As AggregateException

属性值

注解

引发未经处理的异常的任务存储生成的异常,并在调用 Wait 或访问 Exception 属性时将其传播到 AggregateExceptionTasks that throw unhandled exceptions store the resulting exception and propagate it wrapped in a AggregateException in calls to Wait or in accesses to the Exception property. 在对任务实例进行垃圾回收时未观察到的任何异常都将在终结器线程上传播。Any exceptions not observed by the time the task instance is garbage collected will be propagated on the finalizer thread. 有关详细信息和示例,请参阅异常处理(任务并行库)For more information and an example, see Exception Handling (Task Parallel Library).

适用于