The Throwable Class: Root of All Exceptions and Errors
What you'll learn: You'll understand why Throwable sits at the top of Java's exception hierarchy and why only Throwable and its subclasses can be thrown.
The Root of All Throwables
In Java, you cannot throw just any object. The throw keyword only accepts instances of Throwable or its subclasses. Throwable is a special class defined in java.lang that serves as the superclass for all exceptions and errors in Java.
Think of Throwable like the trunk of a tree—everything that can be thrown in Java branches out from this single root. Without being part of the Throwable family tree, an object simply cannot participate in Java's exception-handling mechanism.
Why This Restriction Exists
Java enforces this rule to maintain a consistent exception-handling contract. When you write a catch block, the compiler guarantees you're catching something that extends Throwable. This allows the JVM to reliably manage stack unwinding, store stack traces, and provide exception chaining—features built into the Throwable class itself.
The Throwable class provides essential methods like getMessage(), printStackTrace(), and getCause() that all exceptions inherit. Without extending Throwable, an object wouldn't have these capabilities.
The Two Main Branches
Throwable has two direct subclasses that form distinct branches:
Exception: For recoverable conditions your program should handleError: For serious problems (likeOutOfMemoryError) typically beyond your program's control
Everything you've thrown or caught so far descends from one of these two branches, but both ultimately trace back to Throwable.
Key Takeaway: Throwable is the mandatory superclass for all exceptions and errors in Java; only Throwable and its subclasses can be thrown, ensuring a consistent exception-handling mechanism across the language.