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...

  1. Create a workflow project:

    Create a new Workflow Console Application and name it ErrorHandling.

  2. 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 ...

Get Microsoft Windows Workflow Foundation 4.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.