function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TehNrdTehNrd 

Why can't I catch this system exception?

So I have a SOQL query in a Visualforce page that is returning too many results. This is expected but I would like to be able to catch this error and display a nice clean error message to the user. The problem is that I can't seem to catch this error:

Error:
System.Exception: Too many query rows: 10001

Class.salesWinsVF.search: line 57, column 32
External entry point

Code:
Code:
try{
   for(Opportunity opp : Database.query(queryString)){
      results.add(opp);
   }
}catch (QueryException e){
   system.debug('Why can't I catch this');
}

I've also tried: 

}catch (Exception e){

with no luck.




Message Edited by TehNrd on 08-25-2008 10:53 AM
Rusty12Rusty12
Exceeding governor limits will generate an exception that cannot be handled.
TehNrdTehNrd
Well that's unfortunate.

I guess I will just have to limit the results to 10,000 and then check to see if this was reached and then notify the user.

Thanks for the help.

-Jason


Message Edited by TehNrd on 08-27-2008 11:37 AM
Rusty12Rusty12
you don't have to hardcode the 10,000...because who knows, they may change the limits some day.  check out the getLimitXXXXX() methods in the apex documentation.  there are two flavors for each getLimit method.  one that will tell you how your code is doing against the limit, and another that will tell you what the limit is for the current context (ie. WSDL method vs trigger vs testMethod).

for example, getQueryRows() and getLimitQueryRows() .

or search for "Limit Methods" in the doc.
TehNrdTehNrd
Thanks for that tip, didn't even think of that.