Share via


WorkflowApplicationUnhandledExceptionEventArgs.UnhandledException 속성

정의

워크플로 인스턴스에서 처리되지 않은 Exception을 가져옵니다.

public:
 property Exception ^ UnhandledException { Exception ^ get(); };
public Exception UnhandledException { get; }
member this.UnhandledException : Exception
Public ReadOnly Property UnhandledException As Exception

속성 값

워크플로 인스턴스에서 처리되지 않은 Exception입니다.

예제

다음 예제에서는 예외를 throw하는 워크플로를 호출합니다. 이 예외는 워크플로에서 처리되지 않으며 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();

설명

활동에서 예외가 throw되었지만 처리되지 않은 경우 워크플로 인스턴스를 종료하는 것이 기본 동작입니다. OnUnhandledException 처리기가 있는 경우 이 기본 동작을 재정의할 수 있습니다. 워크플로 호스트 작성자는 이 처리기를 사용하여 사용자 지정 로깅, 워크플로 중단, 워크플로 취소, 워크플로 종료 등의 적절한 처리를 제공할 수 있습니다.

적용 대상