Table of Contents

Class TryCatch

Namespace
Acuit.Pinpoint.Workflows.Activities
Assembly
Acuit.Pinpoint.Workflows.dll

A flow control activity used to control logic based on thrown exceptions.

public class TryCatch : Activity, IActivity
Inheritance
TryCatch
Implements
Inherited Members

Examples

The following example assumes these XML namespaces:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib"
<TryCatch>
     <TryCatch.Try>
       ...
     </TryCatch.Try>
     <TryCatch.Catches>
       <Catch x:TypeArguments="s:InvalidOperationException">
        ...
       </Catch>
     </TryCatch.Catches>
     <TryCatch.Finally>
       ...
     </TryCatch.Finally>
   </TryCatch></code></pre>

Remarks

This is similar to try/catch/finally in C#. Execution logic is as follows:

  • Try is initially executed, watching for a thrown exception.
  • If Try completes without any errors or cancellation, then Finally is executed.
  • If an exception is thrown while Try is executing, then Catches is searched for the first Catch where ExceptionType is the same as or a base class of the thrown exception type.
    • If a match is found, then that Action is executed, and then Finally is executed.
    • If no match was not found, then Finally is executed, and then the exception is rethrown.
  • If an exception is thrown while a CatchAction is executing, then Finally is executed, and then the exception is rethrown, replacing and hiding the original exception caught by the Catch.
  • If an exception is thrown while Finally is executing, then that exception will be the exception thrown out of this TryCatch activity, regardless of whether a previous exception caused Finally to execute.
  • If the activity is canceled while Try is executing, neither Catches nor Finally will occur.
  • If the activity is canceled while a Catch is executing, Finally will not occur.

Cancellation aborts all workflow activity execution. Finally will not execute when the TryCatch execution is canceled.

When an exception is caught, this activity provides a TryCatch_Exception parameter set to the exception (derived from or of type Exception) to the CatchAction.

Properties

Catches

Gets the list of Catch elements to be checked when the Try activity throws an exception.

public Collection<Catch> Catches { get; }

Property Value

Collection<Catch>

Finally

Gets or sets the optional activity to execute when the Try and any necessary activities in the Catches collection complete execution.

public IActivity Finally { get; set; }

Property Value

IActivity

Try

Gets or sets the optional body to execute, watching for exceptions.

public IActivity Try { get; set; }

Property Value

IActivity

Methods

OnExecuteAsync(ActivityContext, CancellationToken)

Derived classes must implement this to perform the activity.

protected override Task OnExecuteAsync(ActivityContext context, CancellationToken cancellationToken)

Parameters

context ActivityContext

The activity context.

cancellationToken CancellationToken

The cancellation token used to request canceling the activity.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

ArgumentNullException

context is null.

InvalidOperationException

A service required by the activity is not available, or a required activity property value is not set.

Exception

An error occurred while performing the activity.