C# – Windows Workflow – TerminateActivity causes workflow to fault

cworkflowworkflow-activityworkflow-foundation

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?

Best Answer

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.