cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

New property (App.OnError) on version 3.21112

Summary: we have a new property on release version 3.21112 of the Power Apps Studio in the App object: OnError, which can be used to handle any errors that are not done in the controls themselves, so that they are not bubbled up to the app and displayed to the user. This will be important in the coming releases as we start showing unhandled errors to users (which currently is not done).

 

More details:

In the release of version 3.21112 of Power Apps Studio, we added a new behavior property to the App object: OnError. This property can be used to handle any runtime errors that were not handled in the app. In this property we get the same scope variables ‘FirstError’ and ‘AllErrors’ as we do in the IfError function, so the app can get information about the origin and where the errors surfaced, in addition to the error kind, message and possible additional details.

 

Furthermore, since that is a behavior property, the app can take actions that they normally couldn’t inside “data” properties, such as sending the error information to a data source or using the Trace function to send it to an Application Insights instance or a Monitor that is connected to the app (although we will be changing the default implementation to do that soon). The App.OnError can also choose which of the errors that it received that will “bubble up” to the application (which would be the case if there were no expressions inside App.OnError).

 

Let's have some examples. This is a very simple app with two labels that do calculations based on a text input control. As we change the value of the text input, some of the calculations start returning errors, and they are shown in the Studio  (both as red 'X' badges and in the App Checker). We call those "unhandled" errors because they were tried to be used as properties of controls, which cannot handle them.

AppOnError-001-DefaultBehavior.gif

 

We could have handled the error directly in the labels. For example, the current expression for the top label is the following:

 

 

"1 / <Value> = " & 1 / Value(TextInput1.Text)

 

 

And we could use the IfError function to replace the error with another value, like in the example below:

 

 

"1 / <Value> = " & IfError(Text(1 / Value(TextInput1.Text)), "<error>")

 

 

Which would "handle" the error in the function itself:

AppOnError-001b-HandlingLocally.gif.png

App.OnError gives makers a "last stop" before the errors are considered unhandled. And since it is a behavior property, it can use functions such as Trace, Patch, and others that are not available in a Text property of a label, for example. Let's do that, by setting App.OnError to the following expression:

 

 

Trace("Error at " & FirstError.Observed & ": " & FirstError.Message)

 

 

And as we interact with the app, we can see that the errors are not displayed anymore in the authoring environment - the App.OnError expression "handled" the errors, by sending them to the Trace function (which we can see the result in the monitor). 

AppOnError-002-TracingErrors.gif

Notice that currently there are also some error events that are being traced to the monitor - we are tracing most of the errors, even if they are properly handled. We received feedback that this is noisy, and we will be removing those, and tracing only those that are unhandled by the app.

 

But maybe we want to not only trace the errors that were not handled by the app, but also "bubble them up" or "rethrow" those errors so that they will get the treatment of other unhandled errors (which, starting in a few weeks, will be to be displayed to the user, both during authoring and when the app is being played back). We can also do that in App.OnError, by using the (currently undocumented, will update this post when the documentation is ready) Error function, which can take either one or multiple errors as a parameter. So if we replace the existing App.OnError expression with this:

 

 

Trace("Error at " & FirstError.Observed & ": " & FirstError.Message); Error(AllErrors)

 

 

We will both see the errors being traced, and the red 'X' badge that indicates that the error was not handled.

AppOnError-003-RethrowingErrors.gif

Notice that you can "rethrow" only a subset of errors. For example, if you don't want the division by zero errors to be shown to the user, we can update the expression to the following:

 

 

Trace("Error at " & FirstError.Observed & ": " & FirstError.Message);
Error(Filter(AllErrors, Kind <> ErrorKind.Div0))

 

 

And in this case the negative square root error will be considered unhandled in the example above.

 

One thing worth mentioning is that App.OnError will run after the error has been returned by an expression. Its goal is to report errors, log them, suppress them, or in general take control of what the user will see when those errors happen. However, unlike a function such as IfError, App.OnError cannot be used to replace an error with another value in the expression.

 

As I mentioned before, in a few weeks we will start showing all unhandled errors to the user. If you don't want the app to have that, you can proactively implement any logic in App.OnError to either completely ignore them (any expression would do, such as "false"), or log / trace them to some place where you can better understand where your users are hitting errors in their apps.

 

As usual, we want your feedback! Let us know if you have any questions, concerns, suggestions or bug reports on the error handling feature!

5 REPLIES 5
iAm_ManCat
Most Valuable Professional
Most Valuable Professional

I will definitely be using this going forward as I've recently found the lack of detail within the monitor sessions to be a blocker (i.e when it just shows multiple 'null' responses that do not indicate where they originated from).

 

Thanks for adding this! 😻


@iAm_ManCat
My blog


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


@CarlosFigueira 
Error-handling is currently done like this in my Power Apps.  Will App.OnError consider the error handled or unhandled?

If(
    IsEmpty(Errors('Attendance List')),
    Navigate('Home Screen'),
    Notify("There was an error", NotificationType.Error)
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

@mdevaney your expression doesn't return any errors - so as far as the app is concerned, there are no unhandled errors. When there are errors in the 'Attendance List', the call to Notify will be made, and it will "succeed" - by showing a banner to the user.

 

However, if there was a call before that - for example, a Patch to the 'Attendance List' data source - and that call returned an error, then yes, the result of the expression below would be considered an unhandled error:

 

Patch(
    'Attendance List',
    Default('Attendance List'),
    { Name: "John Doe", Value: -1 }); // If (-1) is not a valid value for 'Value',
                                      // there will be an error in this expression
If(
    IsEmpty(Errors('Attendance List')),
    Navigate('Home Screen'),
    Notify("There was an error", NotificationType.Error)
)

 

Hope this helps!

What are the acceptable values for the OnError App property?

Hi @GringoInMiami the App.OnError refers to the OnError property of the App object. It's a behavior property, so it can only be defined, not accessed. The screen capture below shows an example of it. Notice that we just announced that the Error Handling feature is not an experimental feature anymore (it's now Preview), and the version where this change was made (3.22082) still hasn't reached all regions. Before that is done we will have the official documentation that talks about that property and other aspects of error handling.

Example of the App.OnError propertyExample of the App.OnError property

Hope this helps!

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (776)