Handling errors
In this task, we are going to create a Sequence workflow with a TryCatch
activity. There will be a dividend assigned with zero, and hence we can generate a divide-by-zero exception deliberately so that we can handle this error in a TryCatch
activity.
How to do it...
Create a workflow project:
Create a new Workflow Console Application and name it
ErrorHandling
.Create a code workflow:
Create a new class file and name it
ErrorHandlingWorkflow.cs
. Fill the file with the following code:using System; using System.Activities; using System.Activities.Statements; namespace ErrorHandling { public class ErrorHandlingWorkflow{ public Activity GetInstance() { Variable<int> divisor = new Variable<int>("divisor", 10); Variable<int> dividend = new Variable<int>("dividend", 0); Variable<int> result = new Variable<int>("result"); DelegateInArgument<DivideByZeroException> eia = new DelegateInArgument...