Two friends had a disagreement about the placement of the return in the following code:
var abc;
try{
//there can possibly be 1 or more answers;
abc = getAnAnswerFromPossibleAnswers("type","key");
} catch(ex){
ex.printStackTrace();
}
//We only want the first answer even if there were more
return abc[0];
One person says the return should go inside the try because otherwise during runtime a null pointer exception (NPE) can be thrown. The other says they tested and never got an NPE - even if the value didn't exist, abc[0] returned an empty object (the test showed it returning empty curly braces).
Must the return go inside the try or is it ok to be outside as in the above snippet?