This documentation is archived and is not being maintained.

WorkflowApplicationUnhandledExceptionEventArgs Class

Provides information about an unhandled exception that occurred in a workflow instance.


Namespace:  System.Activities
Assembly:  System.Activities (in System.Activities.dll)

public class WorkflowApplicationUnhandledExceptionEventArgs : WorkflowApplicationEventArgs

The WorkflowApplicationUnhandledExceptionEventArgs type exposes the following members.

Public propertyExceptionSourceGets the activity that is the source of the unhandled exception.
Public propertyExceptionSourceInstanceIdGets the unique identifier of the activity instance that is the source of the unhandled exception.
Public propertyInstanceIdThe unique identifier of the workflow instance. (Inherited from WorkflowApplicationEventArgs.)
Public propertyUnhandledExceptionGets the Exception that was unhandled by the workflow instance.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetInstanceExtensions<T>Gets the collection of extensions of the specified type. (Inherited from WorkflowApplicationEventArgs.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

If an exception is thrown by an activity and is unhandled, the default behavior is to terminate the workflow instance. 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.

The following example invokes a workflow that throws an exception. The exception is unhandled by the workflow and the OnUnhandledException handler is invoked. 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


.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.