WorkflowApplicationUnhandledExceptionEventArgs.UnhandledException Eigenschaft

Definition

Ruft die Exception ab, die von der Workflowinstanz nicht behandelt wurde.

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

Eigenschaftswert

Die Exception, die von der Workflowinstanz nicht behandelt wurde.

Beispiele

Im folgenden Beispiel wird ein Workflow aufgerufen, der eine Ausnahme auslöst. Die Ausnahme wird vom Workflow nicht behandelt, und der OnUnhandledException-Handler wird aufgerufen. Die WorkflowApplicationUnhandledExceptionEventArgs werden überprüft, um Informationen zur Ausnahme bereitzustellen, und der Workflow wird beendet.

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();

Hinweise

Wenn eine Ausnahme von einer Aktivität ausgelöst und nicht behandelt wird, ist das Beenden der Workflowinstanz das Standardverhalten. Wenn ein OnUnhandledException-Handler vorhanden ist, kann dieser das Standardverhalten überschreiben. Mit diesem Handler kann der Autor des Workflowhosts die angemessene Behandlung bereitstellen, z. B. benutzerdefinierte Protokollierung, Abbruch des Workflows oder Beenden des Workflows.

Gilt für: