Classification of Exceptions
Home ] Up ] Exceptions: What and Why? ] Method Signatures and Exceptions ] [ Classification of Exceptions ] Catching Exceptions ] Throwing an Exception ] Exception Hierarchies ]

 

 

The Throwable Class Hierarchy

Here's what the exception class hierarchy looks like:

Object
    Throwable
        Error
            <specific Errors>
        Exception
            <specific Exceptions>
            RuntimeException
                <specific RuntimeExceptions>

The Throwable Class

The Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or of one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement. Similarly, only this class or one of its subclasses can be the argument type in a catch clause.

A Throwable class instance contains a snapshot of the execution stack of its thread at the time the Throwable was created. It may also contain a message string that gives more information about the error or exception.

Errors

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method, but not caught, since these errors are abnormal conditions that should never occur.

For examples of specific errors, see.

Exceptions

The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.

RuntimeExceptions

RuntimeException is a subclass of Exception which is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.

A method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the execution of the method, but not caught.

Examples of runtime exceptions are:

  • Arithmetic exceptions, such as divide-by-zero, etc.
  • "Pointer" exceptions, such as trying to access an object through a null reference,
  • Indexing exceptions, such as trying to access an array element with an index that is too large or too small.
  • Etc.

Checked Exceptions

Checked Exceptions are exceptions that:

  1. Are not runtime exceptions and:
  2. Are checked by the compiler.

The compiler checks that these exceptions are caught or specified by each method, as appropriate.

Here's a taste of what part of the Throwable class hierarchy looks like in detail:

(Package java.lang)

Object
    Throwable
        Error
            LinkageError
                ClassCircularityError
                CLassFormatError
                ExceptionInitializerError
                IncompatibleClassChangeError
                    AbstractMethodError
                    IllegalAccessError
                    InstantiationError
                    NoSuchFieldError
                    NoSuchMethodError
                NoClassDefFoundError
                UnsatisfiedLinkError
                VerifyError
            ThreadDeath
            VirtualMachineError
                InternalError
                OutOfMemoryError
                StackOverflowError
                UnknownError
        Exception
            ClassNotFoundException
            CloneNotSupportedException
            IllegalAccessException
            InstantiationException
            InterruptedException
            NoSuchFieldException
            NoSuchMethodException
            RuntimeException
                ArithmeticException
                ArrayStoreException
                ClassCastException
                IllegalArgumentException
                    IllegalThreadStateException
                    NumberFormatException
                IllegalMonitorStateException
                IndexOutOfBoundsException
                    ArrayIndexOutOfBoundsException
                    StringIndexOutOfBoundsException
                NegativeArraySizeException
                NullPointerException
                SecurityException

 

 
The page was last updated February 19, 2008