WorkflowApplicationUnhandledExceptionEventArgs 類別

定義

提供有關工作流程執行個體中發生之未處理例外狀況的相關資訊。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
繼承
WorkflowApplicationUnhandledExceptionEventArgs

範例

下列範例會叫用擲回例外狀況的工作流程。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.

屬性

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.

(繼承來源 WorkflowApplicationEventArgs)
UnhandledException

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

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetInstanceExtensions<T>()

取得指定之型別的延伸集合。Gets the collection of extensions of the specified type.

(繼承來源 WorkflowApplicationEventArgs)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於