Skip to content

Power Apps

Power Apps Error Handling Guidelines

Power Apps Error Handling Guidelines Table of Contents Enable Formula-Level Error Management Patch Function Error-Handling Power Apps Forms Error-Handling Po...

Matthew Devaney
Published
Reading time
3 min read

Before you start

Is this guide for you?

Best entry point
Power Apps
Time investment
3 min read

Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/power-apps-coding-standards-for-canvas-apps/power-apps-error-handling-guidelines/. Author: Matthew Devaney.

Power Apps Error Handling Guidelines Table of Contents Enable Formula-Level Error Management Patch Function Error-Handling Power Apps Forms Error-Handling Power Automate Flow Error-Handling IfError Function Handling Unexpected Errors Enable Formula-Level Error Management

Open Power Apps advanced settings and turn on formula-level error management.  This setting enables use of the IfError function , the IsError function and the app’s OnError property . Patch Function Error-Handling

Check for errors anytime data is written to a datasource with the Patch function or Collect Function .  Even if the submitted record(s) are valid, good connectivity and the correct user permissions cannot be assumed.  This is not necessary for local collections stored in memory. // Create a new invoice If( IsError( Patch( 'Invoices' , Defaults( 'Invoices' ), { CustomerNumber : "C0001023" , InvoiceDate : Date ( 2022 , 6 , 13 ) PaymentTerms : "Cash On Delivery" , TotalAmount : 13423.75 } ) ), // On failure Notify(

"Error: the invoice could not be created" , NotificationType.Error ), // On success Navigate( 'Success Screen' ) ) Code language: JavaScript ( javascript ) Power Apps Forms Error-Handling

Write any code should be executed after a Power Apps form is submitted in its OnSuccess and OnFailure properties . If form submission is successful, use the OnSuccess property to control what happens next. Otherwise, use the OnFailure property to display an error message that tells the user what went wrong.

// OnSelect property of the form's submit button SubmitForm(frm_Invoice); // OnSuccess property of the form Navigate( 'Success Screen' ); // OnFailure property of the form Notify(

"Error: the invoice could not be created" , NotificationType.Error ); Code language: JavaScript ( javascript )

Do not write any code after the SubmitForm function used to submit the form. If form submission fails Power Apps will still move onto the next line of code. This can result in loss of data.

// OnSelect property of the form's submit button

SubmitForm(frm_Invoice); Navigate( 'Success Screen' ); Code language: JavaScript ( javascript ) Power Automate Flow Error-Handling

When a Power Automate flow is triggered from Power Apps its response must be checked for errors.  Flows can fail due to poor connectivity.  They can also return a failure response or a result with the incorrect schema.  If Power Apps does not know the flow failed it will continue as normal. // Get customer invoices

If( IsError( GetAllCustomerInvoices.Run( "C0001023" ) ), // On failure Notify(

"Error: could not retrieve customer invoices" , NotificationType.Error ), // On success Navigate( 'Success Screen' ) ) Code language: JavaScript ( javascript ) IfError Function

Use the IfError function to handle calculations that require a different value when an error occurs.  In this example, if gblTasksTotal equals 0 the IfError function will return 0 instead of throwing a “divide by zero” error.

// calculate the percentage of tasks completed

IfError( gblTasksCompleted/gblTasksTotal, 0 ) Code language: JavaScript ( javascript ) Handling Unexpected Errors

An app’s OnError property is triggered when an unexpected error occurs.  An unexpected error is any error that is not handled using the IfError or IsError function.

Use this code to quickly locate the source of unexpected errors and fix them.  Do not leave this on in a production app since the error message is helpful for a developer but is confusing to a user.  If you want to see unexpected errors in a production app use the Trace function and Azure Application insights to silently log the errors.

// unexpected error notification message Notify( Concatenate( "Error: " , FirstError.Message, "Kind: " , FirstError.Kind, ", Observed: " , FirstError.Observed,

", Source: " , FirstError.Source ), NotificationType.Information ); Code language: JavaScript ( javascript ) Did You Enjoy This Article? 😺

Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?

If you have any questions about Power Apps Error Handling Guidelines please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Share this

Tagged

Power Apps

Have a Microsoft 365 topic idea?

Share article suggestions, community session ideas, corrections, or real-world scenarios for future nextM365 learning notes.

Suggest a topic

Keep learning Microsoft 365

Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.

Continue learning

Next action

What to do next

Browse all tutorials →