When I ask myself the first time, how to handle errors in Power Automate. The answer was not that obvious.
Coming from a programming background, I wanted to do something like in the following Java example.
try {
doDangerousStuff();
doMoreDangerousStuff();
} catch (Exception ex) {
doThisInsteadOfDangerousStuff();
} finally {
doThisNoMatterWhat();
}
I want to be able to react on an error for a set of operations. So I tried to find out, how to do a try catch finally with Power Automate.
How To Implement Try Catch And Finally in Power Automate
We do need to solve two problems:
- Group a set of operations, which is done by the curly brackets in Java
- Identify when things go wrong
The short answer how do to error handling in Power Automate is:
- Group operations with scopes to implement Power Automate try catch blocks
- Use Configure run after to do implement catch and finally
You do not understand what I am talking about? No problem, we build a flow step by step that demonstrates how to handle errors.
If you do not want to follow the guide, there is a shortcut: You can use the Microsoft Power Automate Try, Catch and Finally Template. You will have a Try, Catch and Finally example to explore yourself.
To find out how to setup everything, follow the Power Automate try catch example below.
Power Automate Try Catch Example (Step by Step)
We will set up a whole Power Automate try and catch flow step by step. Afterwards we do a test with and without triggering the catch scope.
-
Create a new instant cloud flow with a manual trigger
New Manually trigger a flow
-
Add an input to the trigger
Trigger Add an input
-
Choose type text for the input field
Choose the type of user input
-
Add a scope control
Add Scope control
-
Rename scope to Try
Rename scope
-
Add another scope and rename to catch
New catch scope
-
Configure run after of the Catch scope
Configure run after
-
Check ‘has failed’ option and click on ‘Done’
Has Failed option
-
Add another scope and call rename it to Finally
New Finally scope
-
Configure run after, check all options and click Done
Configure run after of Finally scope
-
Add a Compose operation to Try scope
Compose operation
-
Set Input to expression: substring(triggerBody()[‘text’],1)
Configure Compose
-
Add a Send me an email notification action to Catch scope
Add Send me an email notification
-
Configure Send me an email notification
Send me an email notification Configuration
-
Add a Send me an email notification action to Finally scope
Send me an email notification configuration
-
Do a test run with input: a
Test run with one character
-
Check test run result, try should fail, catch and finally should be executed
Result test run
-
Check mail inbox, there should be mails for catch and finally
Notifications
-
Do another test run with input: abc
Test run with three characters
-
Check test run result, try should pass, catch should be skipped and finally should be executed
Result test run
So for input a the substring expression fails, because it tries to create a substing starting at the second character which does not exists.
For input abc the substring expression works.
I hope you now have an understanding of how scope and the configure run after options can be used to do an error handling in Power Automate.