TryCatch Activity Designer

The TryCatch activity designer is used to create and configure a TryCatch activity.

The TryCatch Activity

The TryCatch activity contains a Try activity, a collection of Catch<TException> and a Finally activity. A Catch<TException> of type TException contains an ExceptionType and an Action. Together they are used to implement a typical exception-based error handling mechanism. A TryCatch activity tries to execute its Try activity. If the Try activity throws any exception, the TryCatch activity uses its Catch<TException> collection to match the exception. If there is a match, then the Action of the corresponding Catch<TException> is executed, serving as the error handling logic for the exception. If the activities in the Try section successfully complete or the activities in the Catches successfully complete, the TryCatch activity executes its Finally activity. For more information, see Windows workflow exceptions.

Using the TryCatch Activity Designer

Access the TryCatch activity designer in the Error Handling category of the Toolbox.

The TryCatch activity designer can be dragged from the Toolbox and dropped on to the Workflow Designer surface wherever activities are usually placed, such as inside a Sequence. This creates a TryCatch activity with a default DisplayName of TryCatch. The DisplayName value can be edited in the header of the TryCatch activity designer or in the DisplayName box of the property grid. The other properties must be edited on the surface of the TryCatch activity designer.

Click the expand button on the right top corner of TryCatch designer to see the Try, Catches, and Finally boxes in the expanded view. To add a catch, click the Add new catch button on TryCatch designer. The button changes to a type combo box. Select an exception type and press ENTER to add the catch. After adding a Catch, the catch area expands and an activity can be dropped into the catch to define the execution logic for the catch. Note that there is a text box on the right side of the expanded catch area. You can name the exception variable using this text box. The exception variable can only be used for activities within the same Catch.

The TryCatch designer does not support editing Catch. If you want to change the exception type, you have to delete the Catch and add a new one. A Catch can be deleted by selecting it and deleting it or by selecting Delete on the context menu that's accessed by right-clicking.

The TryCatch Properties

The following table shows the TryCatchproperties and describes how they are used in the designer.

Property Name Required Usage
DisplayName False Specifies the optional friendly name of the TryCatch activity. The default is TryCatch.
Try False The activity first executed when the TryCatch executes.
Catches False The collection of Catch elements to be checked when the Try activity throws an exception.

You need at least add one activity in Catches or an activity in the Finally block.
Finally False The activity to be executed when the Try and any necessary activities in the Catches collection complete execution.

You need at least add one activity in Catches or an activity in the Finally block.

See also