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 ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second 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.