Throw an Exception!

  • Write Java code utilizing Java Exceptions.

Let's update ArrayIndexedList.get to throw the IndexOutOfBoundsException:

@Override public T get(int index) throws IndexOutOfBoundsException { if (index >= 0 && index < length()) { return data[index]; } else { throw new IndexOutOfBoundsException(); } }

Make a note of the syntax; in particular, be careful with throw v.s. throws keywords.

Run IndexedListTest and see that all tests pass.