Error handling and TRY, CATCH, AND FINALLY are very important tasks in Programing as well in any kind of development & Microsoft Power Automate or Microsoft Flow is no different.
Error handling and TRY, CATCH, AND FINALLY can be easily implemented in MICROSOFT POWER AUTOMATE/MICROSOFT FLOW for handling different different business scenarios.
You can place your main actions inside TRY BLOCK . Due to any exceptions or errors, if TRY BLOCK will get fail then CATCH BLOCK will execute. FINALLY BLOCK will run everytime.
There is Try, Catch, and Finally Template provided by Microsoft Flow Community – https://flow.microsoft.com/en-us/galleries/public/templates/e8e028c6df7b4eb786abdf510e4f1da3/try-catch-and-finally-template
Lets understand this with an example.
- Create a flow with Manual Trigger. This is an example trigger. It can be replaced if required.
- Then add an action SCOPE. Scope Action in Microsoft power automate or Encapsulate a block of actions and inherit the last terminal status (Succeeded, Failed, Cancelled) of actions inside.
Name the scope as TRY. In Try Scope you can define main steps or actions.
- After Try Scope, add another SCOPE “Catch”. Catch Scope will execute in case of a error or exception in Try Scope. You can place your error handling logic in Catch Scope.
- Configure Run After of Catch Scope & select the option “Has Failed” = Yes
- After Catch Scope, add another SCOPE “Finally”. Finally Scope will execute always i.e. in both for failed and successful runs
- Configure Run After of Finally Scope & select the option “Has Failed” = Yes, “is Successful” = YES, “is skipped” = YES & “has timed out” = Yes
- Your final flow should look this