Introduction
This article helps to understand how to simulate the traditional try catch exception block in power automate, apart from scopes and parallel programming.
Scenario
For ease in understanding, we will use the classic example Invoking a rest API and on exception it should use catch block
try
{
// read from rest api
}
catch
{
// send a email to admin stating the operation has been failed
}
Provisioning Action Commands
Power automate provisions three action commands in case of failure which are part of configure run after
- Has Skipped
- Has failed
- Has timed out
The action command is accessible via the three dots available in every action (except every first action of flows or scopes)
Configure Try catch
- In Actions
- Within scope
In Actions
The action that has to be part of catch block can be set to has failed, is Skipped, has timed out as shown in the below screenshot.
For eg: in this scenario, if an email needs to be sent after a rest action failed, we can use the Configure after in the email action
Scoped Actions
Scope is an action in power automate which encapsulates group of actions.
Advantages of using scope are
- Grouping of actions
- Easier & cleaner code
- It makes copy, paste easy
The catch blocks can be defined either sequential or parallel patterns
Sequential Pattern
This is usually a standard way of defining the try catch block which includes the following actions
- Create a scope called try or any valid name like Invoke API
- Create another Scope called Catch and configure run after like shown in the below screenshot
Parallel Pattern
The catch block can be implemented as a parallel block as well, to do so we need to add a scope block as a parallel branch
Note: All the approaches used in this example are valid, the issue you are dealing with determines the best fit for your scenario, PowerAutomate can quickly become cumbersome so choose your steps wisely :)