Fault Handling in a Flowchart Activity Using TryCatch
This topic applies to Windows Workflow Foundation 4 (WF4).
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.
Parameters | Description |
---|---|
promoCode |
The promotion code. Type: String The possible values with description in parentheses:
|
numKids |
The number of children. Type: int |
The CreateFlowchartWithFaults
activity uses a FlowSwitch activity that switches on the promoCode
argument and calculates the discount using the following formula.
Value of promoCode |
Discount (%) |
---|---|
Single |
10 |
MNK |
15 |
MWK |
15 + (1 – 1/
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
Using Visual Studio 2010, open the FlowchartWithFaultHandling.sln solution file.
To build the solution, press CTRL+SHIFT+B.
To run the solution, press F5.
Note: |
---|
The samples may already be installed on your computer. Check for the following (default) directory before continuing.
<InstallDrive>:\WF_WCF_Samples
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.
<InstallDrive>:\WF_WCF_Samples\WF\Basic\Built-InActivities\FlowChartWithFaultHandling
|