Skip to main content

How to Handle Errors in Power Apps with IfError

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

When a formula fails in a canvas app, say a connector call that finds nothing, Power Apps shows a red error banner and the control shows nothing. IfError catches the error and gives you a value to use instead, so the app carries on calmly. Here's how it works, with a real error from the Office 365 Users connector.

Syntax​

Syntax
IfError( Value, Replacement )
IfError( Value1, Replacement1, Value2, Replacement2, ..., DefaultResult )

If Value is an error, IfError returns Replacement; otherwise it returns Value. With several pairs, it checks each in turn and stops at the first error (IfError reference).

Prerequisites​

  • Formula-level error management on. Microsoft notes that IfError won't work correctly if an app has disabled it under Settings → Updates → Retired. In the example app, Disable formula-level error management is Off, so error management is on.
  • Something that can fail. The example's MyManager named formula calls Office365Users.ManagerV2, which returns an error for the signed-in admin, who has no manager. See How to Get a User's Manager in Power Apps.

Step 1: Catch an Error Where You Use It​

Without IfError, the label showed nothing and a banner said Office365Users.ManagerV2 failed: … Resource 'manager' does not exist …. With it:

Text control → Text
IfError(MyManager.displayName, "No manager")

The formula bar with IfError(MyManager.displayName, "No manager"), the preview strip reading No manager with Data type text

Step 2: Catch It Once, at the Source​

If several controls use the value, catch the error where it's created instead. The example wraps the connector call in its named formula and returns Blank() for "no manager":

App → Formulas
MyManager = IfError(
Office365Users.ManagerV2(
MyProfile.id,
{'$select': "id,displayName,mail,jobTitle"}
),
Blank()
);

Now MyManager.displayName is simply blank, and the error banner is gone:

The formula bar with MyManager.displayName, the preview strip reading MyManager.displayName = Blank with Data type text

Each control then decides what to show for a blank; see How to Use the If Function in Power Apps.

Types Must Match​

IfError returns either the value or the replacement, so they must be the same type. Microsoft's example: IfError( 1/x, "#DIV/0!" ) doesn't work, because the text replacement is converted to a number. Convert the first argument instead:

Example
IfError( Text( 1/x ), "#DIV/0!" )

What Went Wrong? FirstError​

Inside the replacement, FirstError describes the error: Kind, Message, Source and more. For example, to log or show the message:

Replacement (example)
IfError( Patch( ... ), Notify( FirstError.Message, NotificationType.Error ) )

Part 6 of the Career Development Plan series uses this pattern when saving a response, with FirstError.Kind to explain a conflict.

Common Mistakes​

MistakeWhat happensDo this instead
A replacement of a different typeAnother errorMake both the same type
Catching every error with Blank()Real failures look like "no data"Show a message that covers both, or check FirstError.Kind
Wrapping each use separatelyRepeated codeCatch once in a named formula

Troubleshooting​

SymptomLikely causeFix
The banner still showsThe error isn't inside the IfErrorWrap the part that fails
IfError seems to do nothingFormula-level error management disabledCheck Settings → Updates → Retired
Still an error, with IfError in placeThe replacement can't be converted to the value's typeMake the types match, for example with Text

FAQ​

IfError or IsError?​

IfError replaces an error with a value. IsError only tells you, true or false, whether something is an error.

Does IfError stop actions after an error?​

Yes, in behavior formulas: the reference shows IfError(Patch(DS1, …), Notify(…), Patch(DS2, …), Notify(…)) stopping after the first failure.

Can I use it in App.Formulas?​

Yes, as long as the replacement is a value, not an action. The example's MyManager does exactly that.

Conclusion​

IfError(value, replacement) swaps an error for something useful. Catch errors once, where the value is created, keep the types the same, and use FirstError when you need to know what failed.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.