I'm having some trouble understanding the implications of the code in my accessor method below. Eclipse's compiler is requiring that I have a return statement after my try-catch block. Does this mean that my getter method will always return null or will it return the item I'm trying to retrieve if it int i doesn't need to be caught by the IndexOutOfBoundsException?
public T get(int i)
{
try
{
return bag[i];
}
catch(IndexOutOfBoundsException e) //if(logiSize < i+1)
{
System.out.println("Collection has fewer items than the index you entered!");
System.out.println("Returning null"); //or should I...?
}
return null;
}
Can anyone help me understand the implications here? Thanks so much!