3 Power Automate Error-Handling Patterns You Must Know
It is important to include error-handling in every Power Automate flow. When a flow fails, the owner should be notified that the flow failed. The message should say why the flow failed and identify the flow run. In this article I’ll share 3 Power Automate error-handling patterns you can re-use in any flow you build.
Table Of Contents: Error-Handling Pattern #1: Try, Catch Finally Pattern • Try Action • Catch Action • Finally Action • Test The Try, Catch, Finally Pattern Error-Handling Pattern #2: Terminate Flow Success or Failure Pattern • Test The Terminate Flow Pattern Error-Handling Pattern #3: Get Flow Run Details URL Pattern • Build The Flow Run Details URL • Send Failure Notification Email With Flow Run Link
Error-Handling Pattern #1: Try, Catch Finally Pattern
We will build a basic flow to learn the first Power Automate error-handling pattern. This pattern, called try, catch, finally, is found in many other programming languages.
- Try – attempt to execute a flow action
- Catch – if the flow action fails, do this action to handle the error
- Finally – run this action regardless of the result
Create a new flow with an instant trigger and add a Compose action.
Then write this expression inside the Compose action to cause an error. Since the number 1 cannot be divided by 0 the flow action will fail.
Next, initialize a variable called varFlowRunFailed to track if the flow failed.
We only want to run the initialize variable action to if the previous action failed. Click the three dots on the initialize variable action and select Configure run after.
Setup the configure run after options as shown below. If the previous flow action fails, the Initialize variable action will run. Or if the previous flow action succeeds, this action will be skipped.
Insert an Office 365 Outlook: Send an email (V2) action to send a notification that the flow completed.
The last step on our Try, Catch, Finally pattern will always run regardless of whether the Compose (try) action succeeded or failed. Go to the configure run after menu and check all of the checkboxes.
Test The Try, Catch, Finally Pattern
To see how the try, catch, finally pattern works, give the flow it a test run. The Compose (try) action will fail, the Initialize variable (catch) action handles the error and the Send an email (finally) action runs afterwards.
Error-Handling Pattern #2: Terminate Flow Success or Failure Pattern
When the test flow run is completed we see the notification “your flow run successfully” appear. This is not true. Our flow’s Compose action failed so the notification should say “flow run failed” instead. Next we’ll improve our Power Automate error handling to show the proper result.
Remove the Send an email (V2) action. Then replace it with the Condition action where the variable varFlowRunFailed is equal to true.
Check all of the checkboxes in the configure the Condition action’s run after settings.
If varFlowRunFailed equals true, send an email notification that the flow failed. Then insert a Terminate action afterwards. Set the Terminate status to Failed.
Otherwise, when varFlowRunFailed is not equal to true send an email and terminate the flow successfully.
Test The Terminate Flow Pattern
Run a test of the updated flow. Now the flow properly shows the message “flow run failed.”
Error-Handling Pattern #3: Get Flow Run Details URL Pattern
When a flow fails we want to inspect the flow run details to see why it failed and fix the problem. Finding the specific flow run that failed can be difficult in Power Automate. To make it easier we can send a link to the flow run details in the failure notification email.
When the email recipient opens the link they are navigated to the flow run details where they can quickly identify what went wrong
Build The Flow Run Details URL
Go to the flow’s If yes condition an add a Compose action.
Use the workflow function to get details about the workflow itself.
Then insert another Compose action to build the flow run URL.
Flow expression #1 gets the environment’s unique identifier.
Flow expression #2 extracts the flow’s unique identifer.
Flow expression #3 finds the flow run’s unique identifer.
Send Failure Notification Email With Flow Run Link
The final step is to include the flow run url as a clickable link in the failure notification email.
Write this HTML code in the body the email and use the Compose action inside the a tag.
<a href="outputs('Compose:_Get_Workflow_URL')"&>Click here</a>to check the flow run details
Now the failure notification email contains a link to the flow run.
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps articles sent to your inbox each week for FREE
If you have any questions about 3 Power Automate Error-Handling Patterns You Must Know please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.
Another great article, thanks Matthew. I think “Or if the previous flow action fails, this action will be skipped.” should be “if the previous flow action succeeds, ……”
I appreciate you letting me know about this error. I’ve updated my article and the downloadable PDF 🙂
It’s great explanation really helps me a lot. As I’m new to.power platform I’m able to understand.. BTW I would like to ask can we use multiple try catch final in a single flow
For eg I have 3 conditions in my flow
1st condition I can use try catch final
2nd condition will it be possible to apply or the flow will be terminated from the 1st condition itself
Yes, you can use multiple actions inside of a try-catch-finally pattern. Instead of using a single action for “Try” use the “Scope” action instead. Then add all of your actions inside the Scope. The catch and finally parts of the pattern remain the same.
Thanks so much. This works great for me until the final step. I struggle with powerbi and I don’t understand how you are configuring the compose actions in the Send Failure Notification Email With Flow Run Link. Are you able to put a video or exact instructions on how to enter this please? Thx so much
To use the compose code, you must paste it into the Power Automate expression editor instead of picking a dynamic value from the list. Sorry, but I do not currently create video content.
Thanks, Matthew! This post saved me a lot of time and nerves. I owe you a beer the next time we meet. Hopefully during the MVP Summit or earlier if you’re around.
You’re welcome. I really do hope they do MVP Summit in person again one day. Fingers crossed.
Very handy explanation!
It took me a while to figure out that the Catch step still runs because it is also set to run if the previous step is skipped.
You can extend the email message by including the error details. Use actions(‘Compose:_Test_Value’).error.message
Yes, the Actions step is a good one to include.