Task.Exception 屬性

定義

取得導致 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 不當結束的 TaskThe AggregateException that caused the Task to end prematurely.

備註

擲回未處理的例外狀況的工作會儲存所產生的例外狀況,並將它傳播至呼叫中的 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).

適用於