RolfWiki


A workflow contains one or more connections to external systems. For example a code activity accesses a database or an erp program. When the external server isn't available an exception will be thrown. How to handle this situation

Solution 1: The FaultHandlerActivity suspends the workflow instance. To resume the instance later I've to provide an administrator dialog with all suspended instances (loaded from the tracking store).
(Question: will the workflow instance resume with the activity which caused the error )


Solution 2: The code activity handles the exception itself with try..catch and retry repeatedly the access to the external system with increasing time spans like a fax device.

What's your opinion to handle this situation Are there any other solutions you recommend


Re: How to design exception handling?

Saurabh Chechi - MSFT


Hi,

As you mention you can handle the situation in either way. I would prefer solution 1 with while activity containing sequence which contains the code activity.

  • While
    • Sequence
      • Code
    • FaultHandler

You can simply eat the exception in the faultHandler and check a boolean in the condition of while. The boolean is set to true in codeActivity when you can access the external system.

When an exception is thrown in an activity, the exception keeps getting thrown further up the service until it is caught. In case no faultHandlers are defined on the instance the instance terminates. In case fault handler is defined for an activity, the activity goes to faulted state and if exception is not rethrown, the instance continues to the next activity (note: in this case the execution will move to while activity after fault is handled on the sequence, this particular instance of sequence goes to faulted state but on next iteration a new instance of sequence is spawned with a new execution context just like regular flow in a while activity)

Hope this helps.






Re: How to design exception handling?

Prashant G Gupta

Hi Saurabh,

I have developed a workflow which contains thousands of lines of code and used a lot of Sharepoint as well as Windows Workflow activities. I am also facing the same issue of handling exceptions thrown by Sharepoint/Windows workflow activities.

I have implemented FaultHandler to catch those exceptions but at class level not at each and every sequence.

Earlier I had a thought of implementing FaultHandler in a way as you have suggested, but the issue is if we will implement while loop, then there should be some user action inside the while loop otherwise the control will go in an infinite loop.

Is there any other way in a sequence Workflow so that the control from FaultHandler can return to the same point from where workflow has thrown an error.

Or this issue can be resolved in State Machine Workflow. Because the errors I am getting is Workflow Internal Errors.

Please let me know your ideas how can I handle it properly so that if a request got stucked in workflow it should not be deleted.

Thankyou very much.








databaseforum