Bhubaneswar, Odisha, India
+91-8328865778
support@softchief.com

Power Automate Exception handling using Try Catch Finally

Power Automate Exception handling using Try Catch Finally

Most of the times when you design a Power Automate flow, you face run time errors due to data issue or environment issues. So this post will explain you how you can handle runtime errors in Power Automate.

Follow the below steps to implement TRY CATCH FINALLY BLOCKS in Power Automate.

Watch the video or scroll down to read the article step bystep.

Step 1: Create a flow with a trigger

Open Power Automate website and create a new flow. For this demo I have created an Instant Flow and taken 2 text parameters.

Step 2: Add a Scope for TRY Block and add actions

To implement TRY CATCH Block, Add an action called as Scope.

Scopes are used to combine multiple action inside a logical group. Inside the scope add a Dataverse action Add New Row. I wanted to created a student record so used Dataverse connector and added Add new Row action and assigned dynamic content to fields. You can rename the scope as TRY.

Before the Try Scope declare a variable as “SUCCESS.”. This variable will be used to store the actual error if there is any error in try scope otherwise the value remains as success if no error.

Step 3: Add a Scope FOR CATCH Block and add actions

Now add another scope after try scope and inside the scope add 2 actions. Parse JSON to parse the body result from Create Student step and extracting the error message from the JSON object and another action to set variable with error message. The error message is the JSON object available as output of parse JSON step.

NOTE: In Parse JSON it requires a schema. To copy the body schema run the flow with error and copy the body request data and use it in Parse JSON using Generate from Sample.

Step 4: Configure RUN AFTER for Catch Scope

This is important step. Click on 3 dots of Catch Scope and choose Configure Run After.

In the configure run after choose has failed. That means the CATCH SCOPE will only be called if TRY SCOPE FAILED.

Step 5 : Add Finally Scope and Configure Run After

Now add a Finally block so that irrespective of TRY block result the Finally block will execute. The finally scope will must execute if TRY BLOCK FAILS and Also for SUCCESS.

Configure Run After for Finally Block.

This time we have selected is Successful or skipped. The Catch scope will be success if there is an Error in Try scope. The Catch block will be Skipped if there is no error in TRY Block. For every scenario the finally block will excute.

TEST NOW: (Failed Result)

The variable store actual result.

TEST NOW: (SUCCESS Result)

Hope this helps.