WorkflowApplicationUnhandledExceptionEventArgs 類別

定義

提供有關工作流程執行個體中發生之未處理例外狀況的相關資訊。

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

範例

下列範例會叫用擲回例外狀況的工作流程。 此例外狀況未由工作流程處理,而且叫用了 OnUnhandledException 處理常式。 系統會檢查 WorkflowApplicationUnhandledExceptionEventArgs 以提供例外狀況的相關資訊,並且終止工作流程。

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

備註

如果活動擲回例外狀況,且該例外狀況未經處理,預設的行為是終止該工作流程執行個體。 如果存在 OnUnhandledException 處理常式,它可能會覆寫這個預設行為。 這個處理常式可讓工作流程主機作者提供適當的處理,例如自訂登入、中止工作流程、取消工作流程,或者終止工作流程。

屬性

ExceptionSource

取得未處理例外狀況的來源活動。

ExceptionSourceInstanceId

取得未處理例外狀況來源之活動執行個體的唯一識別碼。

InstanceId

工作流程執行個體的唯一識別碼。

(繼承來源 WorkflowApplicationEventArgs)
UnhandledException

取得工作流程執行個體未處理的 Exception

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

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

取得指定之型別的延伸集合。

(繼承來源 WorkflowApplicationEventArgs)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於