public double peek() throws NoNextItemException {
That statement tells Java that the
peek
method may throw the
NoNextItemException
. But since this is a
Throwable
exception, it must be caught in any methods that include a call to
peek
.
When you inherit from
IndexOutOfBoundsException (Java Platform SE 7 )[
^], you are telling the system that it is a
RuntimeException (Java Platform SE 7 )[
^], which is unchecked. And unchecked exceptions are not required to be caught if you are allowing the system to take the default action.