Bewerken

Delen via


WorkflowTerminatedEventArgs.Exception Property

Definition

Gets the exception that caused the workflow instance to be terminated.

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

Property Value

The Exception that caused the workflow instance to be terminated.

Examples

The following code example demonstrates how you can use the Exception property to obtain information about an exception that caused a workflow to terminate. The OnWorkflowTerminated method takes a WorkflowTerminatedEventArgs as a parameter. This method is called when the WorkflowTerminated event is raised. The code uses the Exception property get the message associated with the exception that caused the workflow to terminate.

This code example is part of the Sequential Workflow with Parameters SDK Sample from the Program.cs file. For more information, see Workflow with Parameters Sample.

static void OnWorkflowTerminated(object sender, WorkflowTerminatedEventArgs e)
{
    Console.WriteLine(e.Exception.Message);
    waitHandle.Set();
}
Shared Sub OnWorkflowTerminated(ByVal sender As Object, ByVal e As WorkflowTerminatedEventArgs)
    Console.WriteLine(e.Exception.Message)
    waitHandle.Set()
End Sub

Remarks

When the workflow instance is terminated because of an unhandled exception, Exception contains the unhandled exception.

When the workflow instance is terminated by either a host call to WorkflowInstance.Terminate or by a TerminateActivity activity, Exception contains a WorkflowTerminatedException that has its Message property set to a description of the reason for the termination. If the host terminates the workflow instance, it supplies this description in the string parameter to WorkflowInstance.Terminate. If the workflow instance is terminated by a TerminateActivity, the description is supplied by TerminateActivity.Error.

Note

Although in the case of a WorkflowRuntime.WorkflowTerminated event that is not due to an unhandled exception, the workflow runtime engine encapsulates a description of the reason for the termination in the Message property of a WorkflowTerminatedException, it does not necessarily throw this exception.

Applies to

See also