Level of Difficulty: Beginner – Senior.
Power Automate is a powerful tool that works well for integration and even automating workflows. Citizen developers have started adopting Power Automate to automate some of their day-to-day activities. One of the most important parts of a traditional solution development strategy is error and exception handling.
Automation would typically face two kinds of errors/exceptions: Application Error and Business Exception. A business exception refers to any scenario where the process does not meet the defined business rules that the automation was built to include. An application error refers to any ‘unknown’ (unrelated to business rules) error that occurs within the execution of the solution.
Even as citizen development takes off, there remain to be many advantages realised by implementing exception handling. But how do we do it in Power Automate? Here’s how…
Create a Flow
Navigate to Power Automate Cloud and create a new, blank, flow. As part of the exception handling strategy, a variable, named varErrorOccurred, will be used to store a boolean value indicating that the flow either ran successfully or an error occurred, in which case the flow did not run successfully. Scopes will be used to group process steps separately from the steps to be executed when an error occurs. This refers to the try…catch approach (which often includes a finally code block as well). The try block contains all of the process steps that should be executed while the catch block contains all of the steps to be executed if an error occurs during any of the process steps. The finally block contains and steps to be executed, regardless of whether or not any exceptions occurred.
Setup Scopes for Exception Handling
Let’s start by adding three scope to the flow and name them Try, Catch and Finally:
Next, the Catch scope should be set up to run when an error occurs in the Try scope. To do this, click on the three dots in the top-right corned of the Catch scope and select Configure Run After:
Then set up the Finally scope to run after any state by following the same steps above, but this time, for the Finally scope:
Now you can add your actions into the relevant scopes and test your workflow.
Note: You cannot yet initialise variables within a scope, variables need to be initialised at the highest level of the flow, so ensure that you add any Initialise variables actions before the Try scope.