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.
![How to do Error handling similar to try catch in Power Apps Canvas apps1](https://www.sharepointeurope.com/wp-content/uploads/2021/09/How-to-do-Error-handling-similar-to-try-catch-in-Power-Apps-Canvas-apps1-1024x405.png)
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.
![](https://www.sharepointeurope.com/wp-content/uploads/2021/09/How-to-do-Error-handling-similar-to-try-catch-in-Power-Apps-Canvas-apps2-1024x108.png)
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.
![](https://www.sharepointeurope.com/wp-content/uploads/2021/09/How-to-do-Error-handling-similar-to-try-catch-in-Power-Apps-Canvas-apps3-1024x502.png)
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.
![](https://www.sharepointeurope.com/wp-content/uploads/2021/09/How-to-do-Error-handling-similar-to-try-catch-in-Power-Apps-Canvas-apps4.png)
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.
![](https://www.sharepointeurope.com/wp-content/uploads/2021/09/How-to-do-Error-handling-similar-to-try-catch-in-Power-Apps-Canvas-apps5-1024x525.png)
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.
![](https://www.sharepointeurope.com/wp-content/uploads/2021/09/How-to-do-Error-handling-similar-to-try-catch-in-Power-Apps-Canvas-apps6.png)
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/