Patterns for Fault Handling Transition in State Machine
Fault handling is one of the few things that people have asked about in WF4 StateMachine. The most common scenario is to catch an exception when the StateMachine is executing, and then, do either of the followings:
- Remain in the current state
- Jump to a Fault-Handling state and complete the workflow gracefully and restart again.
However, there is no built-in fault-tolerant mechanism in StateMachine. And there are very good reason for that. One, we want to keep StateMachine simple (so it is as easy to understand as Flowchart). Secondly, we really want all the movements within a StateMachine to be driven by Transitions – so if you do implement some fault-handling mechanism, you should be able to draw it in a State diagram and implement it.
Long ago, I did a very small doc on fault-handling. Assuming most of the heavy-lifting of StateMachine happens in Trigger, you can put a Try-Catch in a Trigger and then StateMachine scheduling mechanism should do all other things for you (so you don’t need to schedule activity yourself.
Fault Handling Pattern for Non-Shared Receive/SendReply transition using Try-Catch Handler by adding a Shared Trigger transition
The good thing about this approach is that you can re-use the execution mechanism to prevent a StateMachine from transition. The constraint though, is that it requires your Trigger to be non-shared. I would imagine that this approach would be more useful in Workflow Service scenario (where each “Receive” activity is its own transition).
However, if you already have a shared trigger and you want to handle error this transition, what can you do? The most elegant way that I could think of (at the same when I was drafting it) was to use an intermediate state to catch the error:
Fault-Handling Pattern with Shared Trigger with one Receive and Multiple Fault-Handling SendReply by Using Null Trigger
See if these patterns would be helpful to you!
Isaac @ Shanghai
Comments
- Anonymous
September 13, 2011
The comment has been removed