How to do Error Handling in Power Automate?

Do you want to learn about error handling in Power Automate flow? In this flow tutorial, I will explain exception handling in Power Automate cloud flow. I will show you how to use try catch finally in Power Automate. Finally, I will show you how to do error handling in apply to each in Power Automate.

Sometimes, the flow has failed because of an error. To resolve it quickly, we will notify the user that the error occurred so that it will be easy for the user to configure and fix it. For that, we are going to use a try-catch block by using the ‘Scope‘ action and functionality ‘Configure run after‘.

  • Try – In the try section, we will add a flow action to execute.
  • Catch – In the catch section, we will add a flow action that fails, to handle the error.
  • Finally – It executes an action.

Scenario:

Here, we will cover two examples to handle exceptions; in the first example, The flow triggers manually and requests the user to enter the numerator and denominator value, and in the try section, it performs the function. If any exception occurs in the try section, the catch section executes. Finally, it notifies the user.

In the second example, The flow triggers manually, and then we initialize a variable IsError; by default, set the value to false. In the try section, use the Get all lists and libraries action and provide the SharePoint site Address; it retrieves the information from the selected site. If any exception occurs in the try section, it jumps to the catch section and sets the variable value as true. Finally, using the Terminate action it displays the status as Failed or Succeeded

Follow the below examples to handle exceptions using the Try Catch block and notify users in the Power Automate flow.

Power Automate Error Handling try-catch

Let us see how to add a handle and recover from unexpected errors in a flow using the try catch finally in Power Automate.

Follow the below steps to create a flow to handle exceptions in Power Automate:

Example -1:

Step-1:

Login to Power Automate, click on the select + create option, choose the instant cloud flow, enter the flow name, and click on the create option.

power automate error handling

Step-2:

Expand the trigger action and pass the two number input values for the Numerator and Denominator as below:

power automate error handling try catch

Step-3:

Select +new step, add a scope action, and rename it as Scope try action. Then, add a compose action inside the scope and pass the below expression as an input value, which performs the division based on the two input values.

div(triggerBody()['number'], triggerBody()['number_1'])
error handling in power automate cloud flow

Step-4:

Add a new step, select scope action, rename it as a Scope-catch action, and send an email (V2) action to notify the user that the flow has failed.

  • To – Dynamically select the User’s email
  • Subject – Provide the subject of the email
  • Body – Enter the body of the email
power automate exception handling

Now we will use the functionality ‘Configure run after’, to handle exceptions that occurred in the Try block.

  • Configure run after in Power Automate is a feature that allows us to do certain actions after an action has been completed or failed.
  • If the Try block action fails, is skipped, or times out in this situation, just the Catch block action will run and notify.
  • To enable it, select the ellipsis -> click on ‘Configure run after‘, as you can see in the below image.
try catch in power automate

Here, choose the ‘has failed’ option and click on Done.

How to handle errors in Power Automate

Step-5:

See also  How to create a custom calendar in PowerApps

Add a +new step. Select a Delay action from action triggers and pass the count as 10 and the unit as second.

catch error in power automate

Similarly, configure the configure run after functionality to handle exceptions for the catch block in the delay action as below, And click done.

If the catch block is successful, it will not come to the delay action. The delay action is performed only when the catch block has failed, is skipped, and has timed out.

error handling in power automate cloud flow

Step-6:

Add a new step, send an email(V2) action, and pass the values for To, subject, and Body to notify the user that the flow has succeeded.

exception handling in power automate flow

Our complete flow looks like below:

exception handling in power automate cloud

Test Case-1:

Save and Run the flow manually, Enter the numerator and denominator value, and choose the Run flow option.

catch error message power automate

Once the flow runs successfully as below:

error handling in power automate cloud flow

The user will receive an email in Outlook like the below:

power automate catch error message

Test Case-2:

The flow triggers manually. Enter the numerator and denominator value, and choose the Run flow option.

try catch in power automate

Once the flow runs successfully, like below:

try catch in power automate flow

The user will receive an email in Outlook like below:

try catch finally in power automate

This is how to add a handle and recover from unexpected errors in the Power Automate flow.

Example -2:

In this example, we will add a Try Catch Finally block to handle exceptions inside the flow.

Follow the below steps to achieve this:

Step-1:

In the Power Automate home page, click on the select + create option, choose the instant cloud flow, enter the flow name, and click on the create option.

Step-2:

Add a new step, select the initialized variable action from action triggers, enter the variable name, and choose the variable type as boolean. By default, set the value as False.

Handle exceptions in the Power Automate flow

Step-3:

Add a new step and select the scope action, rename it as a Scope- Try. Then, add a Get all list and libraries action inside the scope. Provide the SharePoint site address to retrieve information from the selected site.

Handle exceptions in Power Automate

Step-4:

Add+ new step and choose the scope action from action triggers and rename it as a Scope- catch. Then, add a set variable action inside the scope catch action.

From the dropdown, select the initialized variable (i.e., Step 2) and set the value as true under expression.

Handle exceptions in Power Automate flow

Now we have to use the ‘Configure run after’ functionality.

  • If the Try block action fails, we will handle the exceptions in the catch block
  • To enable it select the ellipsis -> click on ‘Configure run after‘, as you can see in the below image.
use try catch in power automate

Here, the catch action performs; only the scope try has failed and has timed out. So click on the Done option.

how to handle try catch in power automate

Step-5:

Click on the new step and a scope action from action triggers and rename it as a Scope- Finally. Click on the add an action, and select condition action from action triggers IsError is equal to True.

If yes, select the Terminate action from action triggers and set the status Failed. If No, select the terminate action from action triggers and set the status as Succeeded.

power automate catch error message

Now, we have to use the ‘Configure run after’ functionality.

  • Based on the outcome of the Try block action and catch block, Configure run after for that select the ellipsis -> and select all the options, and click on configure run after like below:
power automate try catch finally

The Scope Finally action is performed when the scope catch action is successful, has failed, is skipped, and has timed out. Select all the options and click Done as shown below:

power automate exception handling

Our completed flow looks like the following:

power automate error checking

Step-6:

See also  Power bi create a date table - Complete tutorial

Save and test the flow by selecting the Test -> Run flow option.

Test case -1:

Here, I have selected the valid SharePoint site address from the dropdown, so it retrieves all the lists and library information for the selected site in the try block without any exceptions.

How to Handle exceptions in the Power Automate flow

Our flow ran successfully and returned the terminate status as succeeded.

how to handle error in power automate

Test case -2:

Here I have passed the Invalid SharePoint site address, so when the flow runs, it handles the exception in the catch section.

catch error in power automate

Our flow ran successfully and returned the terminate status as Failed.

How to Handle exceptions using the Power Automate flow

This is how to add a Try Catch Finally block to handle exceptions using the flow.

Power Automate Error Handling in apply to each

Let us see how to do error handling in apply to each in Power Automate.

Yes, it is possible to handle errors in apply to each control using a flow. So in this example, we will use the below Excel workbook to loop through the rows presented in the Excel table.

We will check the condition of the DOB is equal to today’s date, and then it will send an email to the particular user.

Power Automate Error Handling in apply to each

Follow the below steps to handle errors in apply to each control using flow:

Step-1:

In the Power Automate home page, create an instant cloud flow, enter the flow name, and click on the create option.

Step-2:

Add a new step and select the initialized variable action from action triggers, enter the variable name, and choose the variable type as boolean. By default, set the value as False.

power automate error handling in apply to each

Similarly, Select a new step and add two more initialize variable actions; for the DOB and Email ID, select the variable type as String, and leave the value section blank.

power automate error handling in apply to each

Step-3:

Add a new step and select the scope action rename it as a Scope- Try. Then, add select List rows present in a table action from action triggers; provide the below-required parameters.

  1. Location – Select the Location where the Excel file exists
  2. Document Library – Choose the document library from the dropdown
  3. File – Select the Excel file ( I have selected my Employees Birthday Table)
  4. Table – From the dropdown, choose the table name
Error handling in apply to each power automate

Add an “apply to each” control loop and pass the input as dynamic content values.

Error handling in apply to each power automate flow

Inside the loop, add a set variable action and in the name section from the dropdown, select the initialized variable (DOB). In the value section, pass the dynamic content of the DOB value.

How to handle errors in apply to each control using Power Automate flow

Add a compose data operation and pass the below expression, Just because from the Excel workbook date column returns some random integer value. To display that in the date time format use the below formula.

addDays('1899-12-30',int(variables('DOB')),'yyyy-MM-dd')
How to handle errors in apply to each control using Power Automate

Inside the loop, add a condition control to check if the DOB column is equal to today, If Yes, set the ISError variable as false by using the set variable action.

formatDateTime(utcNow(), 'yyyy-MM-dd')

Similarly, add a set variable action, and in the name section from the dropdown, select the initialized variable (Email). In the value section, pass the dynamic content of the Email value.

If No, leave it blank.

Handle errors in apply to each control using Power Automate

Step-4:

Add+ new step and choose the scope action from action triggers and rename it as a Scope- catch. Then add a set variable action inside the scope catch action.

From the dropdown, select the initialized variable (i.e., Step 2) and set the value as true under expression.

Handle exceptions in Power Automate flow

Now, we have to use the ‘Configure run after’ functionality.

  • If the Try block action fails, we will handle the exceptions in the catch block
  • To enable it, select the ellipsis -> click on ‘Configure run after‘. Here the catch action performs; only the scope try has failed, is skipped, and has timed out. So click on the Done option.
Handle errors in apply to each control using Power Automate flow

Step-5:

See also  How to Populate a Word Template using Power Automate?

Click on the new step and a scope action from action triggers and rename it a Scope- Finally. Click on the add an action, and select condition action from action triggers IsError is equal to True.

If yes, select the Terminate action from action triggers, and set the status Failed. If No, select the send an email(V2) action from action triggers and pass the required fields.

  • To – select the Email Variable from the dynamic content
  • Subject – Provide the Subject of the mail
  • Body – Enter the body of the mail
Example to Handle errors in apply to each control using Power Automate flow

Now, we have to use the ‘Configure run after’ functionality.

  • Based on the outcome of the Try block action and catch block, Configure run after for that, select the ellipsis -> and click on configure run after.
  • The Scope Finally action is performed when the scope catch action is successful, has failed, is skipped, and has timed out. Select all the options and click Done as shown below:
try catch in power automate flow

Our completed flow looks like the following:

try catch finally in power automate

Step-6:

Save and test the flow by selecting the Test -> Run flow option.

Test case -1:

Here, I have passed the correct formula in the compose data operation to retrieve the date column value from the Excel table in the try block without any exceptions. Once the flow ran successfully, like below:

how to handle try catch in power automate

The employees will receive birthday emails as per the birth date presented in the Excel table workbook in Outlook like below:

power automate error handling in apply to each

Test case -2:

In the Scope try block, in the compose data operation, add the below formula as an input, so that the try action fails and jumps to the catch block. Just because by default from the Excel table date column throws a random integer value.

formatDateTime(variables('DOB'),'yyyy-MM-dd')
power automate error handling in apply to each

Save and run the flow. Our flow runs and returns the terminate status as Failed.

Handle errors in apply to each control in Power Automate

This is how to handle errors in apply to each control using Power Automate flow.

Conclusion

I hope now you have learned how to implement exception handling in Power Automate. I have explained, with examples, how to use try catch finally in Power Automate and how to do error handling in apply to each in Power Automate. Whenever you are creating a flow using Power Automate, you should know how to handle errors in Power Automate and how to use try catch finally in power automate.

You may also like:

>