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
textualtextual 

why does select with no rows raise an error when inside a try catch

inside a try / catch, im querying a custom setting and when theres no records to select, i see an error message rather than my catch exception executing. whats up with that? how can i pre-query to ensure a record before this error page gets rendered?

SarfarajSarfaraj

try / catch does not ensure to suppress everything. The specific type you are referring here throws QueryException. If you catch QueryException or its super class Exception only then it will get caught. Example:

try{
    Account a = [Select Id From Account Where Id = null];
}
catch(DmlException e)
{
    
}

 If you need further assistance, please post your code.

VPrakashVPrakash

No SOQL queries are required to retrieve custom settings data. You can use standard custom settings methods to retrieve the map of name and custom settings and check the map is not null and perform your operations. 

 

Use the following links for more info 

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_custom_settings.htm

 

https://help.salesforce.com/apex/HTViewHelpDoc?id=cs_accessing.htm&language=en