Before Refactoring
try{
return list.get(index);
}catch(IndexOutOfBoundsExceptione){
return null;
}
After Refactoring
if(index >= list.size()){
return null;
}
return list.get(index);
Benefits: Avoid too many exceptions since it is not so good to read and it should only be used for an exception flow.