Example of a Custom Exception Class

In Chapter 21, Custom Generic Data Structures, we provide an example of a custom exception class. We declare a reusable class called List that’s capable of storing a list of references to objects. Some operations typically performed on a List are not allowed if the List is empty, such as removing an item from the front or back of the list. For this reason, some List methods throw exceptions of exception class EmptyListException.

Image Good Programming Practice 11.3

By convention, all exception-class names should end with the word Exception.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.