Musings on Workflow Terminated and Exception Handling

When a workflow runs an activity and that activity throws some kind of unhandled exception you would notice that your workflow get terminated. I have see in many articles that explain how the termination happens. Now this is fine only for a rare set of hello world scenarios. When it comes to an enterprise application we usually expect to notify that some error has happened and probably redo our work.


Now if the workflow terminates how the heck are we supposed to re-execute the workflow cause its already terminated right πŸ™‚ and you get the "Workflow not found in persistence store" when you use  a store like SQL . Now this happens when our activity doesn't have a fault handler associated with this it. So one of the solutions we tried for state machine error handling was this.

  1. View the FaultHandlers in the event driven activity in the state.
  2. Add a new Fault activity and set the fault type to System.Exception (this is to capture generic faults and nothing fancier) you can customize this but then again we are trying to avoid workflow termination here.
  3. in the fault handler use a CallExternalMethodActivity.
  4. How to catch the exception - You can promote the Fault property as a dependency property. Another easy way would be to call a methodInvoked(ie the method to be executed before the callExternal method is invoked) and in that access the exception as the fault property in the parent of the callExternalMethodActivity.
  5. You can then pass on what ever data you get to the external method.

I believe there are many more ways of fault handling. I even know of cases where customers hacked the stored procedure of Insertworkflow to avoid workflow deletion on termination.

Anyway this is just on of the easier ways out to clean up incase you have better practices do leave a link πŸ™‚

Comments (3)

  1. Garry Trinder says:

    My thoughts are here:

    Some quotes:

    "The fact of the matter is, you don’t have to do anything special to deal with failures in workflow. It all can be handled in terms of messaging"


    "So, in some cases, it makes perfect sense for the workflow to let the exception bubble through. Not so that the workflow will be terminated, but rather that the message which triggered it would be tried again."

  2. Sajay Antony says:

    I finally found a way to eat the exception . Now need to figure out how to disable state transition πŸ™‚

Skip to main content