Try, Catch, Finally in a Power Automate flow

Flow and Try, Catch and Finally

For most developers the Try, Catch, Finally  construction is a very common way of handling errors.

Within Power Automate flows this pattern is also possible.

Today I setup a flow with a manual start and 3 Scopes. I renamed the scopes to Try, Catch and Finally as shown below.

This is the basic flow for the try-catch-finally pattern.

Try Catch Finally steps  in a Power Automate flow

Try

In the try section I put all the actions that form my main process. The main process may fail anywhere, however I am not going to worry about these failures for now.

Handling exceptions for each action would become quite difficult and it would clutter my flow in Power Automate.

In this pattern I’m assuming that if any error does occur in the Try block of steps that we want to stop the flow and start the error handling part of the process.

Catch

Then for the Catch part of the try, catch and finally pattern I set the run after to has failed

Catch run after settings

In the catch section I add all the failure handling code. This error handling could for example include sending an email with the URL of the flow run to the user that started the flow or maybe even log a support ticket. 

The possibilities are endless.

You could even consider restarting your flow in Power Automate if the flow fails because of an overload of you connector

Finally

For the finally scope I ticked all the boxes in the the run after configuration

Finally run after settings

The only limitation to this solutions that I have found so far it that you can’t collect any exceptions that may be generated. Hopefully soon Microsoft Flow will give the option to collect exceptions.

The closest I’ve got so far with action level exception handling is described in my post Get the result of your failed actions in Power Automate. In this post I managed to get some error details using the result function. However if you planned to collect the error details of every action possible then you might end up with very large flows. I would not recommend that approach for larger flows.

For additional information, for example on how to collect the flow run url and send it to the users or administrators see also, Microsoft Flow – You only need one template to get started. This post also gets you to the Flow template available in your tenant that you could use the implement the basic pattern.

More Power Automate Try Catch Finally post

Implementing a Try, Catch, Finally in Logic Apps

Retrying after failures in Microsoft Flow

14 thoughts on “Try, Catch, Finally in a Power Automate flow

  1. Thank you, Peter! I was wondering about the best way to do try catch. I really like your approach because Scope clearly show what is inside Try, Catch and Finally. Without scopes – it was a total mess.

  2. It’s to bad the try scope will trigger the “Flow run failed.” message instead of showing success due to the catch scope.

      1. I agree with you there. To clarify, my issue is when a “failure” is an acceptable completion of the flow there should be a way to not say it failed.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: