A New Exception Type Must Extend an Existing One

A new exception class must extend an existing exception class to ensure that the class can be used with the exception-handling mechanism. An exception class is like any other class; however, a typical new exception class contains only four constructors:

• one that takes no arguments and passes a default error message String to the superclass constructor

• one that receives a customized error message as a String and passes it to the superclass constructor

• one that receives a customized error message as a String and a Throwable (for chaining exceptions) and passes both to the superclass constructor

• one that receives a Throwable (for chaining exceptions) and passes it to the super class constructor. ...

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.