How To: Microsoft Flow Try, Catch, Finally Block


Last week I found myself in a position where a Microsoft Flow that I manage was having issues and this got me thinking – there has to be a better way to manage error handling within my Flows. Coming from a C# programming background, a try / catch / finally block seemed to be the best approach and to my delight, Microsoft Flow does have a way to implement this logic.

What is a Try / Catch / Finally Block?

Try / Catch / Finally blocks are used in a number of programming languages: C++, Java, Javascript, C# etc.

They are used to manage and handle exceptions within a program and are typically structured like this:

The Try block contains program logic (or part of it) and the Catch block contains the error handling logic (i.e. if some part of the logic within the Try block has an error, the program will jump into the Catch block to execute the error handler).

The Finally block is executed after the Try block’s logic regardless of an error occurring i.e. if there’s no error, it’s executed after the Try block, if there was an error, it’s executed after the Catch block.

This website has a great graphical representation of this logic.

How to implement Try / Catch / Finally block in Microsoft Flow

Try / Catch / Finally logic is implemented within Microsoft Flow using 3 Scope controls and by tweaking their run after conditions. The scope controls will contain the logic we want to execute within each block:

  1. Click New Step within your Flow
  2. Search for “Scope” and select Scope Control from within the results.
Microsoft-Flow-Add-Scope-Control
  1. Click the 3 dots (…) in the top right of the Scope Control and Select Rename. Type the name Try
Microsoft-Flow-Rename-Scope-Control-to-Try
  1. Repeat Steps 1 and 2 to add a new Scope Control directly under the Try scope we just created.
  2. Click the 3 dots (…) in the top right of the new Scope Control and name it Catch.
Microsoft-Flow-Rename-Scope-Control-to-Catch
  1. Click the 3 dots (…) in the top right of the Catch Scope Control and select Configure run after.
  2. Un-check “is successful” and check “has failed” and click Done
Microsoft-Flow-configure-run-after-fail-catch-scope
  1. Repeat Steps 1 and 2 to add a new Scope Control directly under the Try scope we just created.
  2. Click the 3 dots (…) in the top right of the new Scope Control and name it Finally.
  3. Click the 3 dots (…) in the top right of the Finally Scope Control and select Configure run after.
  4. Check all the boxes and click Done
Microsoft-Flow-configure-run-after-finally-scope

That’s it, now you have the structure in place you can split out and place the logic you need within each Scope.

The final layout should look like this:

Note: There’s no way to catpure the actual error message within Flow at this point in time. We hope that Microsoft updates this one day soon!

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts