Table of Contents
• Try, Catch, Finally Pattern
• Group Multiple Actions Inside Of A Scope Action
• Terminate The Flow With A Status Of Success Or Failure
• Notify The Process Owner Of The Flow Failure
• Get The Flow Error Message For The Failed Action
• Include The Flow Run History URL
Try, Catch, Finally Pattern
Check for errors and tell Power Automate how to handle them at possible failure points in the flow.
The Try, Catch, Finally pattern for error-handling pattern is found in most programming languages:
- Try – Attempt to execute one or more flow actions
- Catch – When an error occurs, do these steps next
- Finally – always run these actions whether the previous actions succeeded or failed
Here’s how to create the Try, Catch, Finally pattern with Power Automate.
Configure the “run after settings” as shown for the flow actions below.
Group Multiple Actions Inside Of A Scope Action
When multiple actions have the same error-handling requirements place them inside a scope action. A scope action holds a set of other actions.
Then configure the run-after requirements for the scope. Now any action inside the scope will trigger the error-handling behavior.
Terminate The Flow With A Status Of Success Or Failure
A flow using error-handling will continue to run after it encounters an error. It will end with a status of succeeded even though there was a failure. To overcome this issue, include terminate actions as the final flow steps to ensure to correct status is displayed in the flow run history.
Notify The Process Owner Of The Flow Failure
Alert the business process owner when the flow fails to let them know there was an issue. If no one is notified when the flow fails then it will not get fixed and could continue to happen.
Get The Flow Error Message For The Failed Action
The reason for flows failures are not often not known in advance. This makes writing an error message before-hand difficult. By using the actions expression we can extract a useful error message from the flow action that failed.
Add a failure reason section to the flow failure notification and use this expression.
actions('Compose:_Test_Value')?['error']?['message']
When the flow fails an error message will appear in the flow run history.
Then the message gets included in the flow failure notification to the business process owner who will take action on it.
Include The Flow Run History URL
A clickable link to the flow run details should be added to the failure notification. The message can be forwarded to a developer who can quickly identify the failed flow run in the history. Then they can review the issue and diagnose the problem. To do this, use this following coding pattern:
Flow expression #1 gets the environment’s unique identifier.
outputs('Compose:_Get_Workflow_Details')?['tags']?['environmentName']
Flow expression #2 extracts the flow’s unique identifier.
outputs('Compose:_Get_Workflow_Details')?['name']
Flow expression #3 finds the flow run’s unique identifier.
outputs('Compose:_Get_Workflow_Details')?['run']?['name']
The failure notification email looks like this:
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps articles sent to your inbox each week for FREE
Questions?
If you have any questions or feedback about Power Automate Standards: Error-Handling 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.
This is EXTREMELY helpful and i’ve applied it to a few of my flows but i have picked up an issue which i’m wondering if you have a solution for.
It seems when the Try has a condition or apply to each, any error that comes up within that will show as “Action Failed. No Dependent action succeeded. So in my scenario I have an action that runs a PAD process but i don’t see the actual PAD failure only that useless condition failure.
Attached a picture for your reference.
Any guidance?
Sarah,
Looks like you can detect the error and see the message. Here’s the relevant part of the standards to help you:
https://www.matthewdevaney.com/power-automate-coding-standards-for-cloud-flows/power-automate-standards-error-handling/#Get-The-Flow-Error-Message-For-The-Failed-Action
Hey Matthew,
Some nice tips here, thank you!
One of the things I try to avoid is having a send/terminate in each branch, but having a single send and terminate.
In the branches, I would use variables, then set the variables accordingly to the branch.
This keeps the flow lighter with 2 less steps to maintain….especially when using switch statements in each branch!
Then pass the variables into a send/terminate as it falls past the conditions.
Hi Matthew
Great article! I came across it as I’m just doing the same.
Just a small note:
Instead of using the actions() function (which you need to apply to a specific action that might fail) I use the result() function for the “Try Scope” (result(‘Scope_-_Try’)). It returns an array which you can further filter for ‘Status’ equals ‘Failed’ and then use [‘Error’]?[‘message’] to include in the notification mail.
BR
Gianluca
Does not work as of 9/2024. actions is invalid