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

属性值

注解

存储产生的异常引发未经处理的异常的任务,并将其包装在传播AggregateException对的调用中Wait或对访问Exception属性。Tasks 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).

适用于