views:

154

answers:

1

I'm handling an exception in a FaultActivityHandler, at the end of which, I wish to end the workflow. To that end, I added a TerminateActivity to the fault handler. It looks like this causes the workflow to fault. Is there a better way of doing this? I could use an if-else to check for a an error flag, but this would end up with a lot of nested if-else's where the right side did nothing but skip to the end of the workflow.

Am I missing an obvious way to end the workflow gracefully or should it fault when I end it because of an exception?

+1  A: 

I think the easiest is to add a ThrowActivity with some custom exception and catch that custom exception at the workflow level. That way the workflow will end normally but all other activities are skipped.

Maurice
I guess I'm not thinking in the way intended for WF. It seems to me that a terminal point in the workflow is the natural way to handle this, rather than throwing an exception (the latter of which, btw, is very, very slow on my dev system).
Brian
Which is why you don't throw exceptions around when it isn't needed. But if there is an unexpected issue and you want to stop processing it is the way to go. And in regular code this is no different otherwise you will be adding a lot of extra tests to your code.
Maurice
It seems to me that a simple endpoint would be more suitable. I've already caught the exception and dealt with it, but the workflow needs to now end. Nesting if-else statements seems a poor way to go about this, as does simply throwing the exception again.
Brian