+ Start a Discussion

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:

System.Exception: Too many query rows: 10001

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

   for(Opportunity opp : Database.query(queryString)){
}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
Exceeding governor limits will generate an exception that cannot be handled.
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.


Message Edited by TehNrd on 08-27-2008 11:37 AM
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.
Thanks for that tip, didn't even think of that.