Error handing in Child flows in Power Automate

Error handling in child flows in Power Automate

In the past I’ve looked at error handling for flows and this resulted in the Try-Catch pattern. In this post I will focus on error handling in Child flows.

Parent and child flows

When you create Child flows in Power automate and your child flow fails, you will find that the parent flow will retry your child flow a number of times.

Error handling in child flows in Power Automate Microsoft Office 365 Retrying Child flow

This a bit like knowing that things will fail but retry again and again just in case it may work the next time. For some use cases this might be ok, but quite often it is not. Have you ever thought of using a child flow to handle the copying of a file that may be checked out to someone? Using the retry feature of a child flow this might actually work really well!

Anyway, in this post I want to focus on the failing child flow that simply needs to run once and only once. If it fails then the parent flow should handle the reported error.

For my child flow I will use the following (bad) example.In the middle of my flow I’m going to terminate my flow. Remember my post from a few years ago. Never use terminate in your flows. Well as far as I’m concerned that still applies.

Error handling in child flows in Power Automate Microsoft Office 365 Terminate a child flow incorrectly

Obviously in this flow the terminate happens and the Response back to my parent flow is never completed.

Solution 1 – Change the retry policy

The easiest solution to stopping the retries is to set the Retry policy for the Run a Child Flow action to None. This is quite an easy way to adjust the standard error handling in child flows.

Error handling in child flows in Power Automate Microsoft Office 365 Retry Policy for Child Flow Action

Now as we rerun the parent flow, we will find that the Run a child flow action fails immediately. For most use cases this is a lot better than the 4 retries that Power Automate uses as a default.

Error handling in child flows in Power Automate Microsoft Office 365 image 27

In the above parent flow you would of course still want to implement the Try-Catch pattern as you are likely wanting to handle the failure in the child flow.

Solution 2 – Respond before terminate

So far I’ve looked at how to develop the parent flow. Setting the retry policy to None is probably most of the times a good idea anyway. But we can also do some more in the child flow itself.

A first idea, would be to move to Respond to a PowerApp or flow action. Now the child flow can give a result back to the parent flow before the flow is failed.

Error handling in child flows in Power Automate Microsoft Office 365 Terminate after response

Notice that you will probably want to return some parameters with the details opf the success/failure of the child flow. So that the parent flow can act on the failing child flow.

When the parent flow is now we will find that the response back to the parent flow is happening and all will look good.

Error handling in child flows in Power Automate Microsoft Office 365 Failed Child Flow

The parent flow however is now also looking successful. So as mentioned earlier, you might want to pass a parameter back to the parent flow telling it that something went wrong.

Error handling in child flows in Power Automate Microsoft Office 365 image 28

Once we add the parameter, to the Child flow’s output

Error handling in child flows in Power Automate Microsoft Office 365 image 30

Solution 2 – Child flow with Try Catch

When we however add the try catch to the child flow, we now have tohe option to return positive and negative results back to our parent flow.

Error handling in child flows in Power Automate Microsoft Office 365 image 31

Sending an Ok, result to the parent when the main part of the flow has completed and a Failed result when something has gone wrong.

Now with a simple update to our parent flow, so that we can make sure that any actions that need to run after a successful Child flow are run

Error handling in child flows in Power Automate Microsoft Office 365 image 32

And when we add a send an email action, or any other error handling step into the know branch, our failures in the child flow will be handled by the parent flow..

Error Handling in child flows

Thoughts on Error Handling in child flows

If you want to do Error Handling in child flows by including the retry policy change or if you want to go for the full try catch pattern, it will all depend on the use case. But making sure that child flow failures don’t result in a flow that runs for a very long time, for no purpose at all is an important consideration to make.

Many of my followers who contact me, experience slow running flows. Often this is related to nested apply to each steps that can be avoided. In this case some proper error handling makes the difference between 10 minutes and 0 seconds.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: