Try Catching Workflow Errors In WF4

When comparing how to handle errors within WF3.x and WF4 you immediately see some significant improvements, not just from a logic perspective but also visually.

 

Some of the pain in WF3.x surfaced from the inconsistent behavior and rooted within the designer, when flipping back and forth from the actual workflow and viewing "Fault Handlers" within embedded activities. WF4 not only improves the look and feel of the designer it also logically makes more sense as to what needs to happen within the workflow/activities, when handling different types of exceptions. Since exceptions are driven from the logic within activities, utilizing the new "TryCatch" Activity becomes very familiar since it mimics how we normally catch exceptions through raw code. Since this post is intended to show off WF4, I will quickly give the foundation for handling exceptions within WF3.x. Fault Handlers are used to handle issues, much like what I am going to show you with WF4's TryCatch, however you will see very shortly that it is not as easy to setup. Once you view the FaultHandler part of the workflow, you add the FaultHandler Activities. Again each handler handles a type of exception.

 

Then you can add a Throw Activity...

 

Now for WF4 this process becomes much easier to implement and makes more sense. 

 

Still there is the same concept that exceptions can be caught at the activity level which means that we can add a TryCatch Activity the same way we added FaultHandlers. The image below shows how activities can be placed within the Try Block of the activity.

 

There are three activities that have been added, first a Sequence Activity and then a WriteLine and custom CodeActivity Activity.  Next we can set the type of Exceptions to catch. By clicking on "Add new catch" a dropdown box gives you the option for selecting the exception type. Once the exception type is selected the next thing to add is a Throw Activity. The Exception Property of the Throw Activity sets the exception to be thrown by the activity

 

In conclusion, it is always important to build in good error handling. Working with WF4 is no "Exception". There were many times I was not sure what the issues were with my workflows in 3.x and I spent many nights banging my head. It seems that identifying errors and handing them is much easier with WF4. If you are used to using WF3.x there is still some things to get used to, and it is sometimes hard to teach a dog new tricks. However most of the changes I have seen are significant improvements, and are well worth the time to understand the change.

Currently rated 3.1 by 34 people

  • Currently 3.088235/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: BayerWhite
Posted on: 12/7/2009 at 7:02 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed
Comments are closed