WorkflowApplicationUnhandledExceptionEventArgs.ExceptionSource プロパティ

定義

ハンドルされない例外のソースであるアクティビティを取得します。

public:
 property System::Activities::Activity ^ ExceptionSource { System::Activities::Activity ^ get(); };
public System.Activities.Activity ExceptionSource { get; }
member this.ExceptionSource : System.Activities.Activity
Public ReadOnly Property ExceptionSource As Activity

プロパティ値

アクティビティ。

次の例では、例外をスローするワークフローを呼び出します。 例外はワークフローによって処理され、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 ハンドラーが存在する場合は、この既定の動作をオーバーライドできます。 このハンドラーにより、ワークフロー ホスト作成者は、カスタム ログ記録、ワークフローの中止、ワークフローのキャンセル、ワークフローの終了などの適切な処理を提供できます。

適用対象