throws Statement

Purpose:

To specify what exceptions a method throws.

Mechanics:

<modifiers> <return type> <method name>(<parameter list>) throws <list of Throwables> {
/* Java statements */
}

Example:

public void myMethod() throws Exception {
/* Java statements */
}

Usage:

  • Every method that throws exceptions should declare what exceptions it throws in the method declaration.
  • <list of Throwables> is a space-separated list of the class Throwable and its subclasses.
Back to the Table of Contents
email suggestions to: cs015tas@cs.brown.edu