Skip to main content

Exception class hierarchy from Throwable

Short answer

Throwable is the root; its subclasses are Error (unchecked, e.g., OutOfMemoryError, StackOverflowError) and Exception (checked). Exception includes IOException, SQLException, and RuntimeException (unchecked) with subclasses like NullPointerException, ArithmeticException, IndexOutOfBoundsException, etc. Catch blocks should order most specific first.

Draw an exception class hierarchy to present the errors and exceptions derived from the Throwable class.

In Java, Throwable is the root class of everything that can be thrown. It has two direct subclasses: Error and Exception.

Throwable
 |
 +-- Error                      (unchecked)
 |    +-- VirtualMachineError
 |    |     +-- OutOfMemoryError
 |    |     +-- StackOverflowError
 |    +-- AssertionError
 |    +-- LinkageError
 |
 +-- Exception                  (checked)
      +-- IOException
      |     +-- FileNotFoundException
      |     +-- EOFException
      +-- SQLException
      +-- ReflectiveOperationException
      |     +-- ClassNotFoundException
      +-- InterruptedException
      +-- RuntimeException      (unchecked)
            +-- ArithmeticException
            +-- NullPointerException
            +-- ClassCastException
            +-- IndexOutOfBoundsException
            |     +-- ArrayIndexOutOfBoundsException
            +-- IllegalArgumentException
                  +-- NumberFormatException

Other subclasses of Exception include CloneNotSupportedException and TimeoutException.

Explanation

  • Throwable: provides getMessage() and printStackTrace(); only its objects can be thrown or caught.
  • Error: serious problems in the JVM or system that an application should not try to handle (OutOfMemoryError, StackOverflowError). Unchecked.
  • Exception: conditions that a program can reasonably catch.
    • Checked exceptions (IOException, SQLException, ClassNotFoundException): the compiler requires try/catch or a throws clause.
    • Unchecked (runtime) exceptions (RuntimeException and its subclasses: ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException): caused by programming errors; handling them is optional.

Order of catch blocks: the specific subclass comes first, then its superclass.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Object Oriented Analysis and Design chapter 4 questions →