How do I perform error handling in my Canvas Apps in Power Apps? This is a question I face in almost every training I conduct in Power Apps.
After all why not? Isn’t it the most simplest of requirement to catch an error in an application if something goes wrong so that end-users don’t face the ugly error message.Advertisements
As easy it may sound and quite often we take for granted in so many other platforms, it was not quite that easy in Canvas apps. However to much of our relief, Microsoft have finally introduced functions In PowerFx. They are
- IfError
- IsError
- IsBlankOrError
You can find the pre-release documentation here.
Before you go ahead, a word of caution. As of the time of writing this blog, it is a pre-release documentation and subjected to change. However my personal take on this – It’s something utmost essential and I don’t see a way back from here. It’s only going to improve.
So let’s see the IfError function in action. Let’s take a very very simple scenario to start with.
In the screenshot above, I am dividing by zero. Quite obvious it shall throw an error and here in the function IfError comes in handy.
Below is the output when I click on the “Call Flow” button.
Please note: IfError is an experimental feature and you need to enable the same. To enable this feature navigate to Settings -> Upcoming features -> Experimental -> Formula-level error management and set this to on.
Well that was a very easy one. Let’s take a little more complex scenario. Let’s run a patch statement against DataVerse. In this way we shall learn on how to handle errors if operations on DataVerse or for that any other data source from canvas app throw an error.Advertisements
I change the code on click of the button to below.
I have created a business rule which shall stop any creating any account where name contains test. So this patch statement to create a record shall fail. And the notify statement shall show up.
Let’s go one level up in error handling. Frequently we need to invoke Power Automate flow from canvas apps. What if the flow operation fails? How do we handle errors from Power Automate when invoked from Canvas apps? Let’s check together.
Above is a Power Automate flow where I have forcibly introduced the Divide by Zero error. And this Power Automate flow I am going to invoke from my canvas app.
One thing to remember here. If you want an error to pass the error back to the flow, you need to use the Response action to pass the output of action back to the canvas app.
And you should be able to successfully handle error message.
Hope that helped!
Debajit Dutta
Business Solutions MVP
About the Author:
Reference:
Dutta, D. (2021). How to do Error handling similar to try/ catch in Power Apps Canvas apps. Available at: https://debajmecrm.com/how-to-do-error-handling-similar-to-try-catch-in-power-apps-canvas-apps/