top of page
Search

Power Apps OnError to capture, suppress, and report all errors

Are you tired of your users getting errors in PowerApps? Then check how you can use the OnError property to deal with all of those unhandled errrors. Error messages from bad inputs, functions missing data, or even a Patch function gone wrong can all be dealt with without breaking a sweat. You will learn about OnError, IfError, Error, IsBlankOrError, Left, If, Filter and more. If you have errors in your Power Apps you need this video.


Click the video below to get started!

Click the link below to view more videos from Shane Young:


Key Timestamps:

0:00 Power Apps OnError

1:51 PowerApps IfError and Handled Errors

2:28 Unhandled Errors in Power Apps

3:06 PowerApps App OnError property

5:35 Logging all of your Power Apps errors to a SharePoint data source

9:08 Suppressing Power Apps error messages

11:33 AllErrors

12:44 Using Left to deal with an error message over 255 character limit

14:13 Patch Errors handled vs. unhandled and what to do with them.

15:50 Using the Error function to create your own Error Record


Differences between handled and unhandled errors

Handled errors are those that we anticipate and have logic to deal. Unhandled errors are those that we did not expect and so we don’t have logic ready to handle them.


For example, let’s say your app has the user enter in a number to divide by. If they enter in a zero, Power Apps will throw an error at the top of the screen, “Invalid operation: division by zero”. This is an unhandled error. To turn this into a handled error, we need a way to anticipate the user entering in zero. Using IfError() we can do just that:


IfError(Text(1/Value(TextInput1.Text)), “You cannot divide by zero”)

Now if the user types in a zero the app will show a message inside the app and won’t throw the invalid operation error.


OnError, FirstError, and AllErrors

Many times you cannot anticipate every error that could happen with your app. Perhaps you are trying to connect to Dataverse and a column was deleted, or there was a network timeout when writing a file. Using the App.OnError property gives you a way to run code each time an unhandled error happens.


To retrieve information about the error we can use the AllErrors table or the FirstError record. Generally, the FirstError record will provide us with the information we are looking for. Using FirstError will always give us the same information as using First(AllErrors).


Use Patch for logging errors

Sometimes you might want to capture all the errors that an app is having when troubleshooting an issue. Using the App.Error property and the FirstError record we can use Patch() to write the information into a log. An example would be:


Patch(‘Error Log’, Defaults(‘Error Log’), {Error: FirstError.Message, ControlName: FirstError.Source})


Stopping error messages

There are conditions when you might want to suppress errors. An example from Shane’s video is trying to lookup a user’s profile in Office 365. By using an If() statement in App.OnError, we can choose to ignore any messages related to UserProfile. In the example below, only those errors that don't have the word "UserProfile" will get processed.


If(Not(“UserProfile” in FirstError.Message), Notify(“You got the error: ” & FirstError.Message))


Creating your own error

You can create your own custom errors for conditions that may not throw a technical error. For example, an app should error if users enter a ship date that is before the order date. Using the Error() function we can trigger the code in the App.Error property:


If(ShipDate < OrderDate, Error({Message: “Cannot ship an order before it was ordered”, Kind: ErrorKind.Validation}))


Additional Learning:


Power Platform University

Are you looking for full, personalized Power Platform training? Do you want a mentor to help guide you on your journey? Do you prefer real world content instead of academic concepts? Then Power Platform University from PowerApps911 is for you.

Learn more here.

6,015 views

Comentarios


bottom of page