WorkflowApplicationUnhandledExceptionEventArgs.UnhandledException 屬性

定義

取得工作流程執行個體未處理的 ExceptionGets the Exception that was unhandled by the workflow instance.

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

屬性值

Exception

工作流程執行個體未處理的 ExceptionThe Exception that was unhandled by the workflow instance.

範例

下列範例會叫用擲回例外狀況的工作流程。The following example invokes a workflow that throws an exception. 此例外狀況未由工作流程處理,而且叫用了 OnUnhandledException 處理常式。The exception is unhandled by the workflow and the OnUnhandledException handler is invoked. 系統會檢查 WorkflowApplicationUnhandledExceptionEventArgs 以提供例外狀況的相關資訊,並且終止工作流程。The WorkflowApplicationUnhandledExceptionEventArgs are inspected to provide information about the exception, and the workflow is terminated.

Activity wf = new Sequence
{
    Activities =
     {
         new WriteLine
         {
             Text = "Starting the workflow."
         },
         new Throw
        {
            Exception = new InArgument<Exception>((env) =>
                new ApplicationException("Something unexpected happened."))
        },
        new WriteLine
         {
             Text = "Ending the workflow."
         }
     }
};

WorkflowApplication wfApp = new WorkflowApplication(wf);

wfApp.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
{
    // Display the unhandled exception.
    Console.WriteLine("OnUnhandledException in Workflow {0}\n{1}",
        e.InstanceId, e.UnhandledException.Message);

    Console.WriteLine("ExceptionSource: {0} - {1}",
        e.ExceptionSource.DisplayName, e.ExceptionSourceInstanceId);

    // Instruct the runtime to terminate the workflow.
    return UnhandledExceptionAction.Terminate;

    // Other choices are UnhandledExceptionAction.Abort and
    // UnhandledExceptionAction.Cancel
};

wfApp.Run();

備註

如果活動擲回例外狀況,且該例外狀況未經處理,預設的行為是終止該工作流程執行個體。If an exception is thrown by an activity and is unhandled, the default behavior is to terminate the workflow instance. 如果存在 OnUnhandledException 處理常式,它可能會覆寫這個預設行為。If an OnUnhandledException handler is present, it can override this default behavior. 這個處理常式可讓工作流程主機作者提供適當的處理,例如自訂登入、中止工作流程、取消工作流程,或者終止工作流程。This handler gives the workflow host author an opportunity to provide the appropriate handling, such as custom logging, aborting the workflow, canceling the workflow, or terminating the workflow.

適用於