Fault Handling in a Flowchart Activity Using TryCatch

.NET Framework (current version)

This sample shows how the TryCatch activity can be used within a complex control flow activity.

In this sample, a promotion code and number of children are passed as variables to a Flowchart activity that calculates a discount based on formulae that correspond to the promotion code. The sample includes imperative code and workflow designer versions of the sample.

The following table details the variables for the CreateFlowchartWithFaults activity.

promoCodeThe promotion code. Type: String

The possible values with description in parentheses:

- Single (Single)
- MNK (Married with no kids.)
- MWK (Married with kids.)
numKidsThe number of children. Type: int

The CreateFlowchartWithFaults activity uses a FlowSwitch<T> activity that switches on the promoCode argument and calculates the discount using the following formula.

Value of promoCodeDiscount (%)
MWK15 + (1 – 1/numberOfKids)*10 Note: Potentially, this calculation can throw a DivideByZeroException. So, the discount calculation is wrapped in a TryCatch activity that catches the DivideByZeroException exception and sets the discount to zero.

To use this sample

  1. Using Visual Studio 2010, open the FlowchartWithFaultHandling.sln solution file.

  2. To build the solution, press CTRL+SHIFT+B.

  3. To run the solution, press F5.

System_CAPS_ICON_important.jpg Important

The samples may already be installed on your computer. Check for the following (default) directory before continuing.


If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.


Flowchart Workflows