Error Handling With Power Automate / MS Flow

This article is about how to handle errors in Power Automate. All developers use the  Try, Catch, and Finally construction to handle errors. In Power Automate this is also possible.
 
Let’s setup a manual trigger in Power Automate to see how to handle the error inside the flow.
 
First, you need to login to here using your tenant account. Click on the “Create” in the left-hand side panel and select “Instant Flow” (trigger manually as needed) template.
 
Error Handling With Power Automate / MS Flow
 
You can see the default section, “Manually Trigger a flow”.
 
Error Handling With Power Automate / MS Flow
 
Click on the “Next Step” and it will open the "Choose an action" section. Select the "Initialize variable" action from it.
 
Error Handling With Power Automate / MS Flow 
 
We will first initialize the variable for IsError. We need to enter the Name of variable, select data type, and value from expression. By default, we will set this variable to false.
 
Error Handling With Power Automate / MS Flow 
 
Click on the Next Step and select "Scopeaction.
 
Error Handling With Power Automate / MS Flow
 
We will rename this action by clicking on 3 dots and renaming it to “Try”.
 
Error Handling With Power Automate / MS Flow 
 
 Now, we need to add an action inside the Try scope. Click on the “Add an action” link and select the “Send an HTTP request to SharePoint.
 
Error Handling With Power Automate / MS Flow 
 
Here we need to select our SharePoint site, GET in Method and Uri. In this example, I’ve provided a fake URL as we need to test the flow with the error first.
 
Error Handling With Power Automate / MS Flow 
 
Now, click on the Next Step and select other Scope and rename it with “Catch”. Click on the “Add an action” link and select the “Set variable” action inside Try scope.
 
Error Handling With Power Automate / MS Flow
 
Select the variable name “IsError” from the dropdown list and set the value to true using expression.
 
Error Handling With Power Automate / MS Flow 
 
Now, we need to decide when the Catch scope will execute. For that, we need to “Configure run after” for the Catch scope. Click on the 3 dots in Catch Scope and click the “Configure run after” option.
 
Error Handling With Power Automate / MS Flow
 
Here we need to select when Catch should run. Catch scope is the error handling hence we need to select has failed and has timed out. It means that whenever to Try Scope will be Failed or Timed out, Catch Scope will execute and set the IsError variable to True.
 
Error Handling With Power Automate / MS Flow 
 
Now, click on the Next Step button and select one more Scope and rename it with “Finally”.
 
Error Handling With Power Automate / MS Flow 
 
Click on Add an action and select “Condition” action.
 
Error Handling With Power Automate / MS Flow 
 
In Condition action, select IsError variable from Dynamic content and select true from expression. Now, we will take an action based on the IsError variable value.
 
Error Handling With Power Automate / MS Flow
 
Add and action inside “if yes” and “if no” condition and select “Send an email” action.
 
 
Configure the email To, Subject, and Body as per your requirement and send out the notification to the user about Flow status like failed or success. Here is what I’ve configured.
 
Error Handling With Power Automate / MS Flow
 
The “Try” scope should contain all the actions from the main flow of the process. “Catch” scope is configured to be run only if “Try” fails for whichever reasons. Then the “Finally” scope should run no matter what happens in the previous actions.
 
Click on the 3 dots in Finally Scope and click “Configure run after” option and select all the options.
 
Error Handling With Power Automate / MS Flow 
 
So, here is what our complete flow will look like,
 
Error Handling With Power Automate / MS Flow 
 
First, we need to Save this flow and it’s time to run and test it now. Click on the “Test” link at the top right corner and select I’ll perform the trigger action radio button. Click on the Test and Run flow button.
 
The flow will successfully run and throw the error due to the fake URL we used above in SharePoint to get the response.
 
Error Handling With Power Automate / MS Flow 
 
Error Handling With Power Automate / MS Flow
 
It will execute the "if yes" condition and send out an email notification to the user that flow is failed.
 
Error Handling With Power Automate / MS Flow 
 
Now, we need to test the flow without any error. For that, we will delete the “Send HTTP request to SharePoint” action from Try Scope, save the flow and run it again.
 
Error Handling With Power Automate / MS Flow 
 
Let’s  run the flow again, and it has successfully run without any error. If you notice,  it has already skipped Catch scope as there is no error in Try Scope.
 
Error Handling With Power Automate / MS Flow
 
Flow directly executes the Finally scope ,as we set it  to always run and execute “if no” section is inside that. Because IsError variable is false and sends out an email notification to users that flow is a success.
 
Error Handling With Power Automate / MS Flow 
 
Error Handling With Power Automate / MS Flow 
 
I hope you enjoy this article and let me know if you have any doubts or questions. Happy Learning!! 


Similar Articles