UnhandledExceptionAction UnhandledExceptionAction UnhandledExceptionAction UnhandledExceptionAction Enum

Definición

Especifica la acción que se produce cuando escapa una excepción de la raíz de un flujo de trabajo.Specifies the action that occurs when an exception escapes the root of a workflow.

public enum class UnhandledExceptionAction
public enum UnhandledExceptionAction
type UnhandledExceptionAction = 
Public Enum UnhandledExceptionAction
Herencia
UnhandledExceptionActionUnhandledExceptionActionUnhandledExceptionActionUnhandledExceptionAction

Campos

Abort Abort Abort Abort 0

Especifica que la clase WorkflowApplication debe anular el flujo de trabajo.Specifies that the WorkflowApplication should abort the workflow. El resultado es que Aborted devuelve la llamada realizada al delegado cuando el proceso de anulación se completa.This results in the calling the delegate returned by the Aborted bwhen the abort process is complete. Como razón de la anulación se usa la excepción no controlada.The unhandled exception is used as the abort reason.

Cancel Cancel Cancel Cancel 1

Especifica que la clase WorkflowApplication debe programar la cancelación de la actividad raíz y reanudar la ejecución.Specifies that the WorkflowApplication should schedule the cancellation of the root activity and resume execution. El resultado es que la propiedad Completed devuelve la llamada realizada al delegado cuando el proceso de cancelación se completa.This results in a cakk ti the delegate returned by the Completed property when the cancellation process is complete.

Terminate Terminate Terminate Terminate 2

Especifica que la clase WorkflowApplication debe programar la terminación de la actividad raíz y reanudar la ejecución.Specifies that the WorkflowApplication should schedule termination of the root activity and resume execution. El resultado es una llamada al delegado asignado a la propiedad Completed cuando el proceso de cancelación se completa.This results in a call to the delegate assigned to the Completedproperty when the termination process is complete. Como razón de la finalización se usa la excepción no controlada.The unhandled exception is used as the termination reason. Terminate es la acción predeterminada si no se especifica ningún controlador OnUnhandledException.Terminate is the default action if no OnUnhandledException handler is specified.

Ejemplos

En el ejemplo siguiente se invoca un flujo de trabajo que produce una excepción.The following example invokes a workflow that throws an exception. El flujo de trabajo no controla la excepción y se invoca el controlador de la propiedad OnUnhandledException.The exception is unhandled by the workflow and the OnUnhandledException handler is invoked. El objeto WorkflowApplicationUnhandledExceptionEventArgs se inspecciona para proporcionar información acerca de la excepción y se termina el flujo de trabajo.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;
};

wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
    // Display the exception that caused the workflow
    // to abort.
    Console.WriteLine("Workflow {0} Aborted.", e.InstanceId);
    Console.WriteLine("Exception: {0}\n{1}",
        e.Reason.GetType().FullName,
        e.Reason.Message);
};

wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
    if (e.CompletionState == ActivityInstanceState.Faulted)
    {
        Console.WriteLine("Workflow {0} Terminated.", e.InstanceId);
        Console.WriteLine("Exception: {0}\n{1}",
            e.TerminationException.GetType().FullName,
            e.TerminationException.Message);
    }
    else if (e.CompletionState == ActivityInstanceState.Canceled)
    {
        Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
    }
    else
    {
        Console.WriteLine("Workflow {0} Completed.", e.InstanceId);

        // Retrieve the outputs of the workflow.
        foreach (var kvp in e.Outputs)
        {
            Console.WriteLine("Name: {0} - Value {1}",
                kvp.Key, kvp.Value);
        }

        // Outputs can be directly accessed by argument name.
        // Console.WriteLine("The winner is {0}.", e.Outputs["Winner"]);
    }
};

wfApp.Run();

En el ejemplo siguiente se invoca un flujo de trabajo que produce una excepción.The following example invokes a workflow that throws an exception. El flujo de trabajo no controla la excepción y se invoca el controlador de la propiedad OnUnhandledException.The exception is unhandled by the workflow and the OnUnhandledException handler is invoked. La clase WorkflowApplicationUnhandledExceptionEventArgs se inspecciona para proporcionar información sobre la excepción y se anula el flujo de trabajo.The WorkflowApplicationUnhandledExceptionEventArgs are inspected to provide information about the exception, and the workflow is aborted.

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 abort the workflow.
    return UnhandledExceptionAction.Abort;
};

wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
    // Display the exception that caused the workflow
    // to abort.
    Console.WriteLine("Workflow {0} Aborted.", e.InstanceId);
    Console.WriteLine("Exception: {0}\n{1}",
        e.Reason.GetType().FullName,
        e.Reason.Message);
};

wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
    if (e.CompletionState == ActivityInstanceState.Faulted)
    {
        Console.WriteLine("Workflow {0} Terminated.", e.InstanceId);
        Console.WriteLine("Exception: {0}\n{1}",
            e.TerminationException.GetType().FullName,
            e.TerminationException.Message);
    }
    else if (e.CompletionState == ActivityInstanceState.Canceled)
    {
        Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
    }
    else
    {
        Console.WriteLine("Workflow {0} Completed.", e.InstanceId);

        // Outputs can be retrieved from the Outputs dictionary,
        // keyed by argument name.
        // Console.WriteLine("The winner is {0}.", e.Outputs["Winner"]);
    }
};

wfApp.Run();

En el ejemplo siguiente se invoca un flujo de trabajo que produce una excepción.The following example invokes a workflow that throws an exception. El flujo de trabajo no controla la excepción y se invoca el controlador de la propiedad OnUnhandledException.The exception is unhandled by the workflow and the OnUnhandledException handler is invoked. La clase WorkflowApplicationUnhandledExceptionEventArgs se inspecciona para proporcionar información sobre la excepción y se cancela el flujo de trabajo.The WorkflowApplicationUnhandledExceptionEventArgs are inspected to provide information about the exception, and the workflow is cancelled.

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 cancel the workflow.
    return UnhandledExceptionAction.Cancel;
};

wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
    // Display the exception that caused the workflow
    // to abort.
    Console.WriteLine("Workflow {0} Aborted.", e.InstanceId);
    Console.WriteLine("Exception: {0}\n{1}",
        e.Reason.GetType().FullName,
        e.Reason.Message);
};

wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
    if (e.CompletionState == ActivityInstanceState.Faulted)
    {
        Console.WriteLine("Workflow {0} Terminated.", e.InstanceId);
        Console.WriteLine("Exception: {0}\n{1}",
            e.TerminationException.GetType().FullName,
            e.TerminationException.Message);
    }
    else if (e.CompletionState == ActivityInstanceState.Canceled)
    {
        Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
    }
    else
    {
        Console.WriteLine("Workflow {0} Completed.", e.InstanceId);

        // Outputs can be retrieved from the Outputs dictionary,
        // keyed by argument name.
        // Console.WriteLine("The winner is {0}.", e.Outputs["Winner"]);
    }
};

wfApp.Run();

Comentarios

La función OnUnhandledException se invoca si una excepción escapa de la raíz del flujo de trabajo.The OnUnhandledException function is invoked if an exception escapes the root of the workflow. La clase WorkflowApplicationUnhandledExceptionEventArgs proporciona acceso a la excepción, así como un puntero a la clase Activity que generó la excepción.The WorkflowApplicationUnhandledExceptionEventArgs provides access to the exception as well as a pointer to the Activity that generated the exception. Finalizar es la acción predeterminada si no OnUnhandledException se especifica ningún controlador.Terminate is the default action if no OnUnhandledException handler is specified.

Se aplica a