WorkflowApplicationUnhandledExceptionEventArgs Class

Definition

提供有关工作流实例中发生的未处理异常的信息。Provides information about an unhandled exception that occurred in a workflow instance.

public ref class WorkflowApplicationUnhandledExceptionEventArgs : System::Activities::WorkflowApplicationEventArgs
public class WorkflowApplicationUnhandledExceptionEventArgs : System.Activities.WorkflowApplicationEventArgs
type WorkflowApplicationUnhandledExceptionEventArgs = class
    inherit WorkflowApplicationEventArgs
Public Class WorkflowApplicationUnhandledExceptionEventArgs
Inherits WorkflowApplicationEventArgs
Inheritance
WorkflowApplicationUnhandledExceptionEventArgs

Examples

下面的示例调用了引发异常的工作流。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();

Remarks

如果异常由某个活动引发并且未经处理,则默认行为是终止该工作流实例。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.

Properties

ExceptionSource

获取作为未处理异常的源的活动。Gets the activity that is the source of the unhandled exception.

ExceptionSourceInstanceId

获取作为未处理异常源的活动实例的唯一标识符。Gets the unique identifier of the activity instance that is the source of the unhandled exception.

InstanceId

工作流实例的唯一标识符。The unique identifier of the workflow instance.

(Inherited from WorkflowApplicationEventArgs)
UnhandledException

获取工作流实例未处理的 ExceptionGets the Exception that was unhandled by the workflow instance.

Methods

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetInstanceExtensions<T>()

获取指定类型的扩展的集合。Gets the collection of extensions of the specified type.

(Inherited from WorkflowApplicationEventArgs)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Applies to