Exception handling in Power Automate

Exception handling is the most common practice used in programming to tackle unwanted or unexpected events. Since exception handling deals with anomalies, it avoids program error, flow error and system crashing. 

There are many reasons that can cause exceptions, including expression error, invalid user input, loss of network connection, user attempting to open files that are not available.

The Try Catch mechanism is used to capture exceptions. Try defines a block of statement that may throw an exception. When a specific type of exception occurs, the catch block catches the exception.

Now let us consider a usage scenario to understand Try-Catch mechanism within power automate.

We can use a Power Automate flow to send an HTTP request and based on the response we need to acknowledge the receipt in the CRM. If the response to the HTTP request is ‘true’ we need to change a field in CRM to Success. And if the response is ‘false’ the field in CRM should change to Failed.

There can be scenarios that the HTTP request can hit an error, or any of the actions can hit error and further iteration of the flow will not happen.

HTTP request errorFig.1

Since there is an error in the HTTP template, the step ‘HTTP-POST Import Opportunity’ has failed and therefore further steps in the flow will not be executed. As the CRM field update step is followed by ‘HTTP-POST Import Opportunity’ step, the field in CRM will not get updated.





To tackle this, we can use Try-Catch method.



Add a new step called Scope. It can be renamed to Try

Graphical user interface, text, application

Description automatically generated

Fig.2


Add all actions which needs to be handled for exceptions in the scope. 

Table

Description automatically generated with medium confidence

Fig.3


Add another scope step and add actions to perform in case of exceptions

A picture containing graphical user interface

Description automatically generated

Fig.4

Now click on the three dots of Catch and Configure run after

Chart

Description automatically generated with low confidence

Fig.5

Set up Configure run after by checking the fields as given below

 Graphical user interface, application, website

Description automatically generated

Fig.6

If any action in the Try block has failed or skipped or has timed out, then the catch block will run.

Once the Try-Catch method is configured, even if the ‘HTTP-POST Import Opportunity’ or any of the action execution fails, the Catch block will run and acknowledge the user through CRM.

In the fig below (Fig.7) we can see that action Get a row by ID-Industry Types has failed.

A picture containing graphical user interface

Description automatically generated

Fig.7

As we have already configured the run after setting, the Catch block will run. 

By this approach, the user can be intimated regarding the error in the flow if any.


Comments

Popular posts from this blog

Create HTML table by combining columns from multiple entities

Dynamics 365 CRM Form Switching: A Deep Dive into formSelector and navigate()

Create and Send Emails with Attachments in D365/Dataverse with Power Automate