Exception Handling Using Configure Run After Settings
In this tip we are going to talk about two very important concepts: Scopes and Configure Run After settings. Technically these are two separate features, but when put together they can address important design considerations, including exception handling.
Let’s start with Scopes, which allow makers to configure logically related actions within a single ‘container’. In our scenario, we have a couple actions that we want to group including a Compose message and a Variable. A Scope allows us to group these actions from a design perspective and we can collapse this Scope to save some real estate when editing other parts of our flow
However, this isn’t the only benefit of using a Scope. What this also allows us to do is to detect whether this group of actions collectively succeeds or fails.
What happens if one of these actions fails? What should we do? We can detect these scenarios by using Configure Run After settings. To do this we will create another Scope and call it Catch. Then, we will provide some compensating logic in this Scope such as getting the user profile of the person who ran the (manual) flow. Next, we send an email to that person, so they know it failed. We will also update a Variable that indicates our flow encountered an error.
We only want this Catch Scope to run when we have a failure. To configure this, we need to click on the … (ellipsis) on our Catch Scope and click on Configure Run After.
We will be presented with dialog that asks when we should run our Catch Scope. We only want to run this Scope when our Try Scope – has failed.
Now in true Try-Catch-Finally semantics, that we would experience in a modern programming language, we can also create a Finally Scope that allows us to execute specific actions regardless of the success/failure of our Try/Catch Scopes.
In Microsoft Flow, by default, a subsequent action will only run when the previous action is successful. Since we want our Finally Scope to run in all scenarios, we need to change its Configure Run After settings. In this scenario, we want to enable all options: is successful, has failed, is skipped, has timed out.
We can now go and run our test. In our test we will deliberately get our Try Scope to fail to validate that both our Catch Scope and Finally Scopes are working.
Scopes not only allow makers to organize their flows, but can also be used to logically group related actions together. When Configure Run After settings are configured, makers can handle exceptions and provide compensating logic to address those errors and inform stakeholders of the problem.