You need to sign in to do that
Don't have an account?

retunring null in catch block
Hi All,
Is retunring null in catch block best practice.......
public List<Sobject> getSharedRecordsOfSObject(String query, Set<Id> setSObjectId) {
List<sObject> listShareResult = new List<sObject>();
try {
if(query != null) {
listShareResult = Database.query(query);
}
return listShareResult;
}
catch(QueryException ex) {
system.debug(ex);
return null;
}
}
Regards
Is retunring null in catch block best practice.......
public List<Sobject> getSharedRecordsOfSObject(String query, Set<Id> setSObjectId) {
List<sObject> listShareResult = new List<sObject>();
try {
if(query != null) {
listShareResult = Database.query(query);
}
return listShareResult;
}
catch(QueryException ex) {
system.debug(ex);
return null;
}
}
Regards
Handling exceptions only really makes sense if you can recover from the situation. If returning null means that the calling code will know there was a problem, then its fine. If returning null means the calling code will assume there are no list shares, that probably isn't correct, as there may be some but the code failed trying to extract them. If it means the action the user is trying to perform is going to fail, you may be better letting the exception bubble up to the top level code and displaying it to them.