11.1 Java Exception Hierarchy: Checked, Unchecked & Error

Key Takeaways

  • Throwable is the root of Java’s throwable types, extends Object and has the standard subclasses Error and Exception. Code can also define a direct subclass of Throwable.

  • Checked throwable classes are Throwable and its subclasses outside the RuntimeException and Error branches. A checked exception that can escape a method generally must be declared.

  • RuntimeException, Error, and their subclasses are unchecked. Their possible propagation does not impose a compiler catch-or-declare requirement.

  • Error subclasses such as StackOverflowError, OutOfMemoryError, ExceptionInInitializerError, and NoClassDefFoundError signal severe JVM or linkage failures that applications should normally not catch

  • A custom class that directly extends Exception is checked. One that directly extends RuntimeException is unchecked.

Last updated: November 2026

Java Exception Hierarchy: Checked, Unchecked & Error

Independent prep covering the exception-classification objectives of Official Domain 8 (Handling Exceptions). An exception in Java is an object representing an abnormal event that disrupts the normal flow of instructions during execution. Instead of forcing every method to return special integer error codes and cluttering business logic with if checks, Java separates normal control flow from error-handling code and routes failures up the call stack until a matching handler catches them.

Exam questions in this domain test two foundational skills: knowing exact inheritance relationships under java.lang.Throwable, and predicting whether javac enforces the Catch-or-Specify rule (also called Handle-or-Declare) for a given exception type.

The Throwable Class Hierarchy

An exception object has type Throwable or a subclass. A throw statement takes an expression of an appropriate throwable type or the null type. A catch type must be a throwable class. A throws clause can also name a type parameter bounded by Throwable. Attempting to throw or catch a regular class such as String or Object causes a compile-time error because neither inherits from Throwable.

At the top of the exception tree, Throwable extends java.lang.Object. Its two standard direct subclasses are:

  1. java.lang.Error — Represents failures ordinary applications are generally not expected to recover from, including virtual-machine and linkage errors. Java code can also throw an Error directly, such as AssertionError.
  2. java.lang.Exception — Represents conditions that an application might reasonably want to anticipate, catch, and recover from.

Under java.lang.Exception, one special subclass—java.lang.RuntimeException—acts as the boundary between checked and unchecked exceptions.

Important

Although Throwable and Exception are the parent types of Error and RuntimeException, the compiler treats Throwable itself and Exception itself as checked exception types. Only RuntimeException (and its subclasses) and Error (and its subclasses) are unchecked.


Comparing the Three Categories

Understanding the exact compiler rules and runtime intent for each branch prevents the most common 1Z0-808 classification traps:

CategoryClass Hierarchy PositionCompiler Check (Catch-or-Specify)Typical ExamplesShould Application Code Catch It?
Checked ExceptionThrowable and its subclasses except the Error and RuntimeException branchesChecked — must be caught or declared via throwsIOException, FileNotFoundException, SQLException, java.text.ParseException, ClassNotFoundExceptionDecide where the condition can be handled. A method may propagate a checked exception in its throws clause.
Unchecked Exception (Runtime)RuntimeException and all of its subclassesUnchecked — optional to catch or declareNullPointerException, ArithmeticException, IllegalArgumentException, IndexOutOfBoundsException, ClassCastExceptionSelective — usually indicates a programming bug; fix the logic or validate inputs
ErrorError and all of its subclassesUnchecked — optional to catch or declareStackOverflowError, OutOfMemoryError, ExceptionInInitializerError, NoClassDefFoundErrorNormally No — indicates JVM or environment failure; recovery is rarely safe

Tracing Checked vs. Unchecked Compilation

Consider how javac reacts when three methods throw three different Throwable subtypes without declaring throws:

import java.io.IOException;

public class HierarchyRules {
    public void throwChecked() {
        // throw new IOException("disk error"); // DOES NOT COMPILE: unreported exception IOException
    }

    public void throwRuntime() {
        throw new IllegalArgumentException("bad input"); // Compiles: RuntimeException is unchecked
    }

    public void throwError() {
        throw new AssertionError("broken invariant"); // Compiles: Error is unchecked
    }
}

Notice that both throwRuntime() and throwError() compile cleanly with no try-catch block and no throws clause. By contrast, uncommenting throw new IOException("disk error"); fails compilation because IOException extends Exception without extending RuntimeException.

What if a method declares throws Throwable or throws Exception? Because both Throwable and Exception are checked types, any caller must either catch them or redeclare them:

public class BroadChecked {
    static void risky() throws Throwable {
        throw new Throwable("root checked type");
    }

    public static void main(String[] args) {
        // risky(); // DOES NOT COMPILE: unreported exception Throwable
        try {
            risky();
        } catch (Throwable t) {
            System.out.println("Caught: " + t.getMessage());
        }
    }
}

Even though risky() could theoretically throw an unchecked Error or RuntimeException at runtime, its declaration allows a checked Throwable to escape, so the compiler forces main to handle or declare Throwable.


Error Subclasses vs. Application Exceptions

Exam questions often ask whether catching an Error is legal versus whether it is good practice. Those are two separate questions:

  • Syntactically legal? Yes. Because Error extends Throwable, writing try { ... } catch (Error e) { ... } or try { ... } catch (Throwable t) { ... } compiles and executes if an Error is thrown on that thread.
  • Recommended practice? No. Errors such as OutOfMemoryError or StackOverflowError mean the JVM itself has exhausted critical runtime resources or failed to link/initialize a class (NoClassDefFoundError, ExceptionInInitializerError). Attempting to continue execution after catching an Error often leaves the program in an unstable state.

Warning

Do not confuse NoClassDefFoundError (an unchecked linkage error, for example when a required definition cannot be loaded or the class was already marked erroneous) with ClassNotFoundException (a checked Exception thrown by reflection APIs such as Class.forName("com.example.Missing")).


Creating Custom Exceptions

When designing custom exception classes in Java SE 8, the superclass you choose immediately determines whether callers face a compile-time check:

class InvalidOrderException extends Exception { // Checked exception
    public InvalidOrderException(String message) {
        super(message);
    }
}

class NegativeQuantityException extends RuntimeException { // Unchecked exception
    public NegativeQuantityException(String message) {
        super(message);
    }
    public NegativeQuantityException(String message, Throwable cause) {
        super(message, cause);
    }
}

Throwable exposes standard constructors—no-arg (), (String message), (Throwable cause), and (String message, Throwable cause)—along with getMessage(), printStackTrace(), and getCause(). Calling super(message) passes the detail message up to Throwable so e.getMessage() returns that detail message, which can itself be null.


Advantages of Java's Exception Mechanism

The Java SE 8 Programmer I objectives highlight why exceptions are preferred over legacy status codes:

  1. Separates error handling from regular logic — Normal code stays inside try without repeated if (status != OK) branches after every call.
  2. Propagates errors up the call stack automatically — Helper methods do not need to manually forward error codes through five intermediate callers.
  3. Groups and differentiates error types via inheritance — Catching IOException handles FileNotFoundException and every other I/O subclass uniformly, while specific catch clauses can still handle subtypes individually.
  4. Makes checked outcomes visible at compile time — Ordinary callers must handle or declare checked exceptions. A handler can still discard an exception, so the compiler does not guarantee recovery.
Loading diagram...
Selected Java SE 8 Throwable Types
Test Your Knowledge

Which class sits directly between java.lang.Object and java.lang.Exception in the Java SE 8 standard library?

A

java.lang.Error

B

java.lang.Throwable

C

java.lang.RuntimeException

D

java.io.IOException

Test Your Knowledge

A method header is declared as public void load() throws Throwable. What happens when a caller invokes load() inside a method that has no try-catch block and no throws clause?

A

Compilation succeeds because Throwable includes Error and RuntimeException

B

Compilation succeeds, and any thrown exception becomes unchecked at runtime

C

Compilation fails only if load() actually throws a checked subclass inside its body

D

Compilation fails because Throwable itself is a checked type under the Catch-or-Specify rule

Test Your Knowledge

Which pair consists strictly of unchecked types that do not require a try-catch block or throws clause to compile?

A

ExceptionInInitializerError and NumberFormatException

B

FileNotFoundException and ArithmeticException

C

ClassNotFoundException and StackOverflowError

D

java.text.ParseException and NullPointerException

Sections you finish are checked off in the contents.