In this article, we will learn about error handling. Error handling is basically if any error happens in a flow it can do something to handle it. Like taking custom actions, such as ignoring it or applying a retry pattern.
For example, if we have a numeric value to be entered in a variable. Instead of a numeric value, a string value is entered. This will lead to the failure of normal execution.
To avoid this, power automate allows us an option of "Configure run after" to handle errors. Configure run after allows us options like, is successful, has failed, is skipped, has timed out. These options are used for error handling.
Handling Errors In Power Automate
- Let's first create an error in a flow. Create a manually triggered flow. Add a text input for variable Age. Click on the New step.
- Select Initialize variable from actions. Add variable name Age as type Integer. Click on the New step.
- Now, select Set variable name Age to value Age that we are accepting. Click on the New step.
- Save and Test the flow. Enter a numeric value and Run flow.
- It will give you an error that Age variable can only support integer value. Here, when the value 20 entered, it accepts as a string value.
- The error can be handled by converting the string "20" into numeric 20. Go back to edit your flow. Remove the previous value of Age from the Set variable.
- Click on Add dynamic content. In Expression, type int() function. This function will allow our string value to get converted into an integer value.
- Click on Dynamic content. Put the cursor in int() function and click on Age under Manually trigger a flow.
- Here, our Age variable which comes through manually triggered flow is of type string. The int() function converts it into integer value. Click on OK.
- We have our expression value for Age variable.
- Save and Test the flow. Enter the value 20 and Run flow.
- Our flow successfully runs without any error.
- Now, suppose while testing we enter a string value "abc" and click on Run flow.
- Here, we get an error again.
- Go back to edit your flow. After Set Variable action click on the New step.
- Select Compose (Data Operation) from actions. Write a message you want to display when an error occurs. Click on three dots in the right-hand side top corner of Compose.
- Click on Configure run after.
- Select "has failed" option. When the Set Variable action fails then the message in Compose will be shown. Click on Done.
- Now, Save and Test the flow. Enter the string "abc" and click on Run flow.
- Here, you can see Set Variable action has been failed. So, the Compose action display's the message.