Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition
by Khalid A. Mughal, Rolf W. Rasmussen
5.9. throws Clause
A throws clause can be specified in the method protoype.
... someMethod(...) throws <ExceptionType1>, <ExceptionType2>,..., <ExceptionTypen> { ... }
Each <ExceptionTypei> declares a checked exception. The compiler enforces that the checked exceptions thrown by a method are limited to those specified in its throws clause. Of course, the method can throw exceptions that are subclasses of the checked exceptions in the throws clause. This is permissable since exceptions are objects, and a subclass object can polymorphically act as an object of its superclass (see Section 6.1, p. 226). The throws clause can have unchecked exceptions specified, but this is seldom used and the compiler does not check them.
Handling of checked exceptions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access