Saturday, October 8, 2011

Exception of type 'System.Workflow.ComponentModel.WorkflowTerminatedException' was thrown

This is the error you see when you use the TerminateActivity in Windows workflow foundation/Visual Studio workflow development for SharePoint applications. The main reason behind why this exception is "We are terminating the current running workflow in middle and framework rises the exception that the workflow is terminated".

The main use of this TerminateActivity is for terminating workflow only. But, I do not recommend to use this activity in your workflows as this is a kind of exception which is throwing by WWF framework. Instead we could try

  • Filter the logic by if, else and end the workflow.
  • By throwing the exception from your code and by using the FaultHandler catch the exception and write it to logs.
  • If we want to stop the workflow, we may write the code to stop the workflow by using CancelWorkflow(workflow).
  • Even if you use the activity if you do not want to  see the above exception in the workflow logs then you might do this. From the "Properties" window the attribute "Error" – fill this field with some text like "Workflow terminated as the reviewers not found for the current item" etc. So that user can understand the error clearly instead of the exception details.

Hope it helps.

No comments:

Post a Comment