UnhandledExceptionAction Énumération

Définition

Spécifie l'action qui se produit lorsqu'une exception s'échappe de la racine d'un flux de travail.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
Héritage
UnhandledExceptionAction

Champs

Abort 0

Spécifie que l'objet WorkflowApplication doit abandonner le flux de travail.Specifies that the WorkflowApplication should abort the workflow. Cela entraîne l’appel du délégué retourné par Aborted lorsque le processus d’abandon est terminé.This results in the calling the delegate returned by the Aborted bwhen the abort process is complete. L'exception non gérée est utilisée comme motif d'abandon.The unhandled exception is used as the abort reason.

Cancel 1

Spécifie que l'objet WorkflowApplication doit planifier l'annulation de l'activité racine et reprendre l'exécution.Specifies that the WorkflowApplication should schedule the cancellation of the root activity and resume execution. Cela entraîne un appel au délégué retourné par la propriété Completed quand le processus d’annulation est terminé.This results in a call to the delegate returned by the Completed property when the cancellation process is complete.

Terminate 2

Spécifie que l'objet WorkflowApplication doit planifier l'arrêt de l'activité racine et reprendre l'exécution.Specifies that the WorkflowApplication should schedule termination of the root activity and resume execution. Cela entraîne un appel au délégué attribué à la propriété Completed lorsque le processus d’arrêt est terminé.This results in a call to the delegate assigned to the Completedproperty when the termination process is complete. L'exception non gérée est utilisée comme motif d'abandon.The unhandled exception is used as the termination reason. Terminate est l'action par défaut si aucun gestionnaire d'événements OnUnhandledException n'est spécifié.Terminate is the default action if no OnUnhandledException handler is specified.

Exemples

L'exemple suivant appelle un workflow qui lève une exception.The following example invokes a workflow that throws an exception. L'exception n'est pas prise en charge par le workflow et le gestionnaire OnUnhandledException est appelé.The exception is unhandled by the workflow and the OnUnhandledException handler is invoked. L'objet WorkflowApplicationUnhandledExceptionEventArgs est inspecté de façon à fournir des informations sur l'exception, et le workflow est arrêté.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();

L'exemple suivant appelle un workflow qui lève une exception.The following example invokes a workflow that throws an exception. L'exception n'est pas prise en charge par le workflow et le gestionnaire OnUnhandledException est appelé.The exception is unhandled by the workflow and the OnUnhandledException handler is invoked. L'objet WorkflowApplicationUnhandledExceptionEventArgs est inspecté de façon à fournir des informations sur l'exception et le flux de travail est abandonné.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();

L'exemple suivant appelle un workflow qui lève une exception.The following example invokes a workflow that throws an exception. L'exception n'est pas prise en charge par le workflow et le gestionnaire OnUnhandledException est appelé.The exception is unhandled by the workflow and the OnUnhandledException handler is invoked. L'objet WorkflowApplicationUnhandledExceptionEventArgs est inspecté de façon à fournir des informations sur l'exception et le flux de travail est annulé.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();

Remarques

La fonction OnUnhandledException est appelée si une exception s'échappe de la racine du flux de travail.The OnUnhandledException function is invoked if an exception escapes the root of the workflow. WorkflowApplicationUnhandledExceptionEventArgs fournit l'accès à l'exception ainsi qu'un pointeur vers l'objet Activity ayant généré l'exception.The WorkflowApplicationUnhandledExceptionEventArgs provides access to the exception as well as a pointer to the Activity that generated the exception. Terminate est l’action par défaut si aucun gestionnaire OnUnhandledException n’est spécifié.Terminate is the default action if no OnUnhandledException handler is specified.

S’applique à