I'm working on writing tests for someone else's code and they have an try/catch around a SELECT statement. Is it possible to ever get an exception in something like the below code block as long as it is being returned to a list? I'm trying to find out if I need to cover the exception block or if I can just remove it.
I know it can happen if you are returning the results to a single object and it doesn't have any results to return, but I don't think it is possible if you return to a list. I'm trying to find if there is an official answer that I can point to if I'm questioned on why I'm removing the try/catch.
public static void processOpportunity(Id opportunityId) {
List<Opportunity> opportunities;
try {
opportunities = [SELECT Id, Name FROM Opportunity WHERE Id = :opportunityId];
}
catch (Exception ex) {
System.debug('Exception: ' + ex.getMessage());
// log exception
}
// do stuff with opportunity
}