web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to trap errors whe...
Power Apps
Answered

How to trap errors when loading a data source.

(0) ShareShare
ReportReport
Posted on by 49

How to trap errors when loading a data source.

 

I am creating a function to display a collection retrieved from a table by ClearCollect() on the screen or insert it into another table.
Is there any way to detect an error in ClearCollect() or Collect()?

 

The method of using IsEmpty() or CountRows()=0 cannot determine if the read failed, because the state where the result of ClearCollect is zero is sometimes correct.

 

It would be very nice if there was a simple way to nest a function into IsError to catch it, for example, as follows
IsError(Patch())

 

Thank you for your answer.

Categories:
I have the same question (0)
  • Fuku-Shima Profile Picture
    49 on at

    I was able to catch the error when loading the data source by trying the following:
    [1] Publish an app with the following code set to Button.OnSelect

    ClearCollect(Collection,DataSourceName);
    If(
     IsError(CountRows(Collection)),
     Notify("Err"),
     Notify("NotErr")
    )

    [2] Delete the SharePoint list that was set in the app[1].

    [3] Click the button in app[1] .

     

    It seems that in version 3.21123.25, it is not possible to use IsError to catch errors in the process of retrieving data from the Collect data source, but
    However, it seems to be possible to catch the error by using a function such as CountRows on the collection after getting the data.

    However, I don't think this is wise because I can't be sure that CountRows(Collection) will always return the correct error.

    Do you have any additional information or advice?
    Thank you in advance.

  • Verified answer
    CarlosFigueira Profile Picture
    Microsoft Employee on at

    What is currently happening is that the error from the data source is being inserted into the collection as an error record (I briefly talked about those in this post). When the CountRows function tries to count the rows of the collection and it contains an error record, it will return the error itself, which is why this works for you. You can get a similar result if you try to check for the first element of the collection. We are probably going to change this behavior over the next couple of weeks so that the [Clear]Collect function itself will return an error, so that it will be easier to check the error with an expression such as the following:

    If(
     IsError(ClearCollect(Collection, DataSourceName)),
     Notify("Err"),
     Notify("NotErr")
    )

    So to make sure that your expression will work now and when this change is made, you can use something along the lines of

    Set(collectResult, ClearCollect(Collection, DataSourceName));
    If(
     IsError(collectResult) Or IsError(First(Collection)),
     Notify("Err"),
     Notify("NotErr"))

    Hope this helps!

  • Fuku-Shima Profile Picture
    49 on at

    CarlosFigueira.

    Thanks for the reply.


    I'm relieved to hear that IsError(Collect()) will be able to catch errors when retrieving data.

    Until then, we will have to deal with
    I guess using First rather than CountRows will give better performance.

     

    Thank you for your help. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 633

#2
11manish Profile Picture

11manish 588

#3
Valantis Profile Picture

Valantis 457

Last 30 days Overall leaderboard