I'm implementing a fixed sized Queue in java which uses a constant size ArrayList as underlying container, where my front() method is supposed to return front element of Queue .
public T front(){
try{
if(isEmpty())
throw new Exception("Queue is Empty- can't return Front element.");
return arrayList.get(frontIndex);
}catch (Exception e){
System.out.println(e);
}
}
By coding in above way , I want front() to return a value only if no Exception is thrown ,however as expected compiler show me "Missing return statement." So , is there any way I can make the function return only if no Exception is thrown.