A while back I write about a Try – Catch construction in Microsoft Flow. Within my Catch I then sent email with some limited information such as the title of the triggering item. This is of course great to identify the item causing the error but you might want more.

Then last week  I wrote about Flow Analytics and finding your failed flow. Today I’m going to take this a bit further.

Something has gone wrong in my flow and I want to get the details within my flow:

Get Item action in Flow showing exception

So in this case I would like to include the status, message and source returned by my failing Get Item. I generated this error by trying to get item 0 from a list in SharePoint.

{
"status": 404,
"message": "Item Not Found\r\nclientRequestId: ffe594bf-a0ee-49eb-8ec2-d5663c537fcd\r\nserviceRequestId: c7666e9e-5046-5000-bd79-d17875df57cb",
"source": "https:/ /mytenant.sharepoint.com//_api/SP.APIHubConnector.GetListItem(listName='634dead0-b2c0-4a31-a11b-f548877c18ee',itemId='0')",
"errors": [
"-1",
"Microsoft.SharePoint.SPConnectorException"
]
}

You could now set 3 variable with

body('Get_Item')?['Status']
body('Get_Item')?['Source']
body('Get_Item')?['Message']

3 variables, status, source and message
And this would probably work but would you really want to clutter your flows with these Set Variable actions every time you have an action that could fail?

Initializing the variables

How can we handle the flow failures while still keeping control over the flows.

I’m going to go back to my Try / catch post.

By moving my Set Variables into the Try / Catch we’re getting one step closer to where we want to be.

Try Catch pattern in my Flow with Power Automate

But now how do we handle a flow with many steps that could possible fail? We don’t just want to clutter the Scope – Catch action with a lot of actions collection the results form all potentially failing actions.

 

 

Microsoft Flow - Advanced Error Handling - Throw in flow Microsoft Flow, Microsoft Office 365 setbody

First after each potentially failing action I’m setting a variable body with the result of the action that I called. And within my Catch I’m setting the 3 variables So that I have the details of the failure.

Microsoft Flow - Advanced Error Handling - Throw in flow Microsoft Flow, Microsoft Office 365 catchvariables

One small problem through my catch will not happen anymore as my body is set successfully.

This is where we need to introduce the throw in flow. All I need to do is make something fail so that an error occurs and my catch will run. In my case I’m just setting an integer variable to a string value.

Microsoft Flow - Advanced Error Handling - Throw in flow Microsoft Flow, Microsoft Office 365 trycatchthrow

And now all I need to repeat is the Throw scope wherever I want to handle an error.

 

 

 

 

 

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

3 thoughts on “Microsoft Flow – Advanced Error Handling – Throw in flow”
  1. this is a good post. however, I would like to group all my actions under one Scope – Try. If anything fails within that scope, how do I get the error message? In your example, you can get error by body(‘Get_Item’)?[‘Message’], but when you have multiple actions, how do you know which one failed?

Leave a Reply

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

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading