Power Automate Try Catch Finally: Error Handling in Flows

Power Automate Try Catch Finally Error Handling in Flows 1

When I ask myself the first time, how to handle errors in Power Automate. The answer was not that obvious.

Coming from a programming background, I wanted to do something like in the following Java example.

try {
  doDangerousStuff();
  doMoreDangerousStuff();
} catch (Exception ex) {
  doThisInsteadOfDangerousStuff();
} finally {
  doThisNoMatterWhat();
}

I want to be able to react on an error for a set of operations. So I tried to find out, how to do a try catch finally with Power Automate.

How To Implement Try Catch And Finally in Power Automate

We do need to solve two problems:

  • Group a set of operations, which is done by the curly brackets in Java
  • Identify when things go wrong

The short answer how do to error handling in Power Automate is:

  • Group operations with scopes to implement Power Automate try catch blocks
  • Use Configure run after to do implement catch and finally

You do not understand what I am talking about? No problem, we build a flow step by step that demonstrates how to handle errors.

If you do not want to follow the guide, there is a shortcut: You can use the Microsoft Power Automate Try, Catch and Finally Template. You will have a Try, Catch and Finally example to explore yourself.

To find out how to setup everything, follow the Power Automate try catch example below.

Power Automate Try Catch Example (Step by Step)

We will set up a whole Power Automate try and catch flow step by step. Afterwards we do a test with and without triggering the catch scope.

  1. Create a new instant cloud flow with a manual trigger

    Power Automate Try Catch New Flow

    New Manually trigger a flow

  2. Add an input to the trigger

    Power Automate Try Catch Trigger Add Input

    Trigger Add an input

  3. Choose type text for the input field

    Power Automate Try Catch Trigger Input

    Choose the type of user input

  4. Add a scope control

    Power Automate Try Catch Add Scope

    Add Scope control

  5. Rename scope to Try

    Power Automate Try Catch Rename Scope

    Rename scope

  6. Add another scope and rename to catch

    Power Automate Try Catch Add Catch Scope

    New catch scope

  7. Configure run after of the Catch scope

    Power Automate Try Catch Configure run after

    Configure run after

  8. Check ‘has failed’ option and click on ‘Done’

    Power Automate Try Catch Configure Run Afer Has Failed

    Has Failed option

  9. Add another scope and call rename it to Finally

    Power Automate Try Catch Finally scope

    New Finally scope

  10. Configure run after, check all options and click Done

    Power Automate Try Catch Finally Configure run after

    Configure run after of Finally scope

  11. Add a Compose operation to Try scope

    Power Automate Try Catch Add Compose

    Compose operation

  12. Set Input to expression: substring(triggerBody()[‘text’],1)

    Power Automate Try Catch

    Configure Compose

  13. Add a Send me an email notification action to Catch scope

    Power Automate Try Catch Send me an email notification

    Add Send me an email notification

  14. Configure Send me an email notification

    Power Automate Try Catch Catch notification

    Send me an email notification Configuration

  15. Add a Send me an email notification action to Finally scope

    Power Automate Try Catch Finally notification

    Send me an email notification configuration

  16. Do a test run with input: a

    Power Automate Try Catch failed test run

    Test run with one character

  17. Check test run result, try should fail, catch and finally should be executed

    Power Automate Try Catch Failed Test Run result

    Result test run

  18. Check mail inbox, there should be mails for catch and finally

    Power Automate Try Catch Mails

    Notifications

  19. Do another test run with input: abc

    Power Automate Try Catch Test run abc

    Test run with three characters

  20. Check test run result, try should pass, catch should be skipped and finally should be executed

    Power Automate Try Catch just finally test run

    Result test run

So for input a the substring expression fails, because it tries to create a substing starting at the second character which does not exists.

For input abc the substring expression works.

I hope you now have an understanding of how scope and the configure run after options can be used to do an error handling in Power Automate.

Leave a Comment

Your email address will not be published.