Basically, we want to be able to control if we want an error. At this time Flow does not let you easily throw an error.
There is a Terminate action which is awesome, I use it in every Flow or Logic App I create.
The Terminate Action will terminate the Run immediately. Terminate will not allow other actions to execute, even if the ‘Configure Run After’ is set to Failed, Skipped.
This can be a headache trying to implement a way to easily Fail an action. While allowing the Flow to continue running the ‘Configure Run After’.
We will use a Try – Catch method. Basically we will use ‘Scope’ actions to house different parts of our actions. You can think of ‘Scopes’ like a way to organize your Flow.
Add them into your Flow just like any other Action.
Try – Where your original flow design will be placed.
Catch – This is where we ‘Catch’ – Meaning we will only run this Scope if the above Scope has a Failed Action
First add a ‘Initialize variable‘, define the type as Boolean, and call this variable Exception.
Next add two(2) ‘Scopes’
Next we want to only run the Catch Scope, if the Try scope has failed.
To do this, simply click the Three(3) dots on the Action and click ‘Configure run after’
Now deselect ‘is successful’ and select the ‘has failed’, and ‘has skipped’ checkbox. Click Done
Next, to trigger an error in the Try Scope, add a ‘Set Variable‘, and select the Boolean from above.
Now, inside the value use the expression null.
The Set Variable should look like this now:
Since our Catch block will run if Try fails, our run will show as Successful. We can change this by adding a ‘Terminate’ action
Add any other error handling you wish inside the Catch scope, some examples include:
- Email to Support that Flow has failed
- Different type of business processing
- Delete a record
- Rename a record
- Service Bus – dead lettering
TIP: When adding other actions inside the Catch scope make sure to make the Terminate action last
Here is a Test run:
This is a great method for executing an error, Its fast and simple, and can be used many times in the same Flow.
Thanks for reading!