Syntax
|-throws-ClassTypeList-|
Description
A throws clause is used to declare any checked exceptions that can result
from the execution of a method or constructor:
A throws clause is declared as follows:
public Object pop() throws EmptyStackException { ... }
The throws clause specifies that the method pop can throw an
EmptyStackException. If any ClassType mentioned in a throws clause
is not the class Throwable or a subclass of Throwable, a compilation error occurs. It is
permitted but not required to mention other unchecked exceptions in a throws
clause.
For each checked exception that can result from execution of the body of a method or
constructor, a compilation error occurs unless that exception type or a superclass of that
exception type is mentioned in a throws clause in the declaration of the
method or constructor.
A method that overrides or hides another method including methods that implement abstract
methods defined in interfaces, may not be declared to throw more checked exceptions than
the overridden or hidden method.
Syntax diagrams
abstract keyword
throw keyword
Source: The Java Language Specification. Copyright (C) 1996 Sun Microsystems, Inc.