Exploring Formula-level Error Management in PowerApps

We have already discussed Named Formulas, Find and Replace, and the ParseJSON function in our previous blog(s).

What is Formula-level Error Management?

Formula-level Error Management allows us to create custom errors to improve app usability and gather valuable error information.

How to Enable Formula-level Error Management Feature?

Assuming you have already created an app and are using the latest version of PowerApps Studio, follow these steps to enable the feature:

  1. Click on Settings on the top bar of the screen.
  2. Select Upcoming Features.
  3. Choose the Preview Features option and search for “Formula” in the top search bar.
  4. Enable the Formula-level Error Management feature.
    Setting

How to use Formula-level Error Management?

Previously, we used IFERROR to manage errors by providing the error-prone code as the first parameter and an error message as the second parameter. Now, you can handle specific types of errors using the Error function.

Earlier, we handled errors generically like this.

IfError(Text(1/0), "Divide by zero")

Now, you can specify the type of error.

IfError(Text(100/Value(TextInput1.Text)),Error({Kind:ErrorKind.Div0,Message:"Divide by 0 error"}))

There are multiple options for Error Kind, and you can also access FirstError and AllErrors for better error handling.

 FirstError

Using FirstError

FirstError provides the error stack for the first error found. You can use it as follows.

IfError(Text(100/Value(TextInput1.Text)),Error({Kind:ErrorKind.Div0,Message:FirstError.Message & " Divide by 0 error"}))

Error

Hope this helps.

Connect with me on LinkedIn.


Similar Articles