Get error message and URL from failed Power Automate flow
When using Power Automate, it's common for actions to fail for various reasons. Ideally, we want to capture this error and take action based on it. Write it to a log, send an email, or take some other action instead of letting it fail repeatedly until we receive a call from users saying something isn't working.
In this example, we'll use the Try/Catch pattern to simplify the process. To trigger an error, we'll try to divide two numbers by zero.
The Try/Catch Pattern
The Try/Catch Pattern is very useful in Power Automate. You will add two Scope actions to your workflow. One is the "Try," where your main logic occurs. The second is the "Catch," which is configured to run only if something in our Try Scope fails.
Manually trigger a flow
- Add the Manually trigger a flow action with two number input parameters.

Try to do something
- Add a Scope action, and rename it to "Try".
- For this example, we'll add a Compose action and then divide our two numbers.
div(triggerBody()['number'],triggerBody()['number_1'])

Catch the error
- Add another Scope action right after our previous Scope and call it "Catch".
- Click the ... in the Scope and select Configure Run After.
- Check "has failed" and "has timed out". This means the Catch Scope will only run if the previous Try Scope has failed or timed out.

- You will see your connecting arrow turn red and have a little note next to it.

- Add a Filter Array action inside our Catch Scope. Our error will be in an array, and we want to filter it so that it only returns items that failed.
- Set the From array to Filter to the following, where "Try" is the name of our scope defined above.
result('Try')
- Set the row expression to item()?['Status'] is equal to Failed.
item()?['Status']

- Add a Compose action, which we will use to capture the error message. Rename it to Compose Error Message and set the Input to the following expression:
body('Filter_array')[0]['error']['message']

- Suppose you want to capture the URL that links directly to the instance of the workflow that failed (very handy). In that case, we can concatenate a few workflow variables together in another compose with the following expression:
concat('https://make.powerautomate.com/', workflow()['tags']['environmentName'], '/flows/', workflow()['name'], '/runs/', workflow()['run']['name'])

- Finally, it can be confusing if our workflow has errors, but it finishes successfully. By adding this Catch logic, we're catching the error, and technically, the workflow no longer failed. So, we can add a Terminate action here so that it shows as failed in the run history.

Test without an error
If you run your workflow and add two valid numbers, like 16 and 4, your workflow should run successfully with no errors. Notice your Catch scope does not get executed.

Test with an error
Now test dividing by zero. Your Try will fail, and your Catch will execute.

If you expand your two Compose actions, you should see the error message and the Workflow Run URL.

You can now do whatever you want with these values. Write them to a SharePoint list, a Dataverse Table, or send an email!
Member discussion