Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 38 ยท Error Handling

Run After and Try/Catch/Finally in Flows

Handle failures on purpose: configure run after for succeeded, failed, skipped and timed-out actions, build try, catch and finally scopes, and read errors with the result function.

Every flow eventually fails: a password expires, a service is down, a file is missing, a user types text where a number should be. A beginner's flow stops at the first failure and nobody notices. A reliable flow expects failure, decides what should happen, tells the right person, and cleans up. Power Automate has no try keyword, but a feature called run after gives you the same structure.

This lesson explains run after, the try/catch/finally pattern with scopes, how to read the details of the failure, and how to end the run with the right status. The examples are JavaScript stand-ins that model the control flow, since the designer cannot run here.

How run after works

Every action runs after the action above it. By default it runs only if the previous action succeeded. In the action's three dots menu choose Configure run after to change that. For each previous action you can tick any combination of four states:

State Meaning
is successful The previous action completed normally (the default)
has failed The previous action returned an error
is skipped The previous action did not run because something before it failed
has timed out The previous action exceeded its time limit

If an action's run-after conditions are not met it is skipped, and skipping cascades: the actions after it are skipped too, unless they are configured to run after "is skipped". In the run history a failed action is red, a skipped one is grey.

Try, Catch, Finally with scopes

Put the risky steps inside a Scope called Try. Add a second scope called Catch that runs after Try has failed or timed out. Add a third called Finally that runs after Catch in every case: succeeded, failed, skipped, timed out.

flowchart TB
    T["Scope: Try<br/>actions that may fail"] -->|"succeeded"| F["Scope: Finally"]
    T -->|"failed or timed out"| C["Scope: Catch<br/>notify, log, undo"]
    C -->|"any outcome"| F
    F --> E["End: Terminate Failed<br/>if the Try failed"]

Catch is skipped if Try succeeds, so Finally must be configured to run after Catch even when Catch was skipped.

Set up like this:

  1. Catch -> Configure run after on Try: tick has failed and has timed out, untick is successful.
  2. Finally -> Configure run after on Catch: tick all four (successful, failed, skipped, timed out).

If Try succeeds, Catch is skipped and Finally still runs because "is skipped" is ticked. This is the step people forget, and without it the cleanup is skipped on the happy path.

JS Stand-in: try, catch and finally

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Reading what went wrong

Inside Catch, you usually want to know which action failed and why. The result() function returns the results of all actions directly inside a scope as an array. Each element holds fields such as name, status, code, error (with message) and outputs.

  1. Add Filter array with the From value @result('Try') and the condition @equals(item()?['status'], 'Failed').
  2. Take the first failed action: @first(body('Filter_array')).
  3. Read its message: @first(body('Filter_array'))?['error']?['message'] and its name: @first(body('Filter_array'))?['name'].

Also useful: workflow() returns information about the flow and the run (names, run id, environment), which you can add to an alert message together with a link to the run. A small Compose action that builds the message keeps the Catch scope readable.

Limit: result() only reports actions directly in the scope; for actions nested deeper (inside a loop inside the scope) the result shows the container's status, so check the run history for the inner detail, or add an inner scope.

JS Stand-in: find the failed action in a result array

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Ending the run honestly

When a failure is caught and handled, the run history may show the flow as Succeeded, because the failure did not stop the run. That hides problems from anyone watching the run list. After the Catch work, add a Terminate action with status Failed and a clear code and message if the failure matters (see Terminate). If the failure is an expected business outcome (an optional step), let the run finish as succeeded.

Alerting and compensation

A Catch scope usually does a mix of these:

  • Notify: post to a Teams channel or email the owner with the flow name, run link and message. Avoid emailing every user for every failure; send to a shared channel the team watches.
  • Log: append a row to a SharePoint list or Dataverse table with time, flow, item id and error. A log makes patterns visible.
  • Compensate: undo what the Try scope did before failing, such as deleting a half-created record, so the data stays consistent.
  • Requeue or flag: mark the item as "needs attention" so a person can fix it and resubmit.

Common mistakes

  • Ticking "has failed" on a Catch but forgetting "has timed out".
  • Forgetting "is skipped" on Finally.
  • Putting the Catch inside the Try scope, so it is skipped when the scope fails. They must be siblings.
  • Catching everything and carrying on silently: always notify or terminate.
  • Using the same failure message for every error: include the action name and message.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A Catch scope is configured to run after Try only. Which states should be ticked?

    Catch should run when the Try scope failed or timed out, not on success.
  2. 2. Why must a Finally scope tick 'is skipped' for the Catch scope?

    On the happy path Catch is skipped; without that tick the Finally scope would be skipped too.
  3. 3. Which function gives you the status and errors of the actions in a scope?

    result('Scope_name') returns an array of action results.
  4. 4. After a handled failure the run history shows Succeeded. How do you mark the run Failed?

    Terminate lets you choose the final status.

Summary

  • Run after lets an action run when the previous one succeeded, failed, was skipped or timed out.
  • Build Try, Catch and Finally as sibling scopes, with Catch after failed or timed out and Finally after all four states of Catch.
  • Use result() with Filter array to find the failing action and its message.
  • Notify, log and compensate in Catch, then Terminate as Failed when the failure matters.

Next: Retry Policies, Timeouts and Throttling