1 Why This Topic Now
Imagine taking this topic in week 3 or 4, when you didn't know what a class is, what a superclass is, or what a subclass is. It would have been impossible! But now you are strong students — you know classes, superclasses, subclasses, and inheritance. This is the perfect time.
Exception handling in Java is built entirely on the class hierarchy. Every exception is an object, every exception type is a class, and those classes are organized in a carefully designed inheritance tree. Understanding this tree is the key to writing precise, effective error handling.
2 The Throwable Family Tree
All exceptions in Java descend from a single root: Throwable. This is the ultimate superclass of everything that can be thrown with the throw keyword and caught with catch. Let's see the full family tree:
Red = Error branch — do NOT catch these
Orange = Exception — the recoverable parent class
Light Red = RuntimeException and subclasses (e.g., ArithmeticException, NullPointerException)
Blue = Other exceptions (e.g., IOException, SQLException) — we will learn the difference later
3 The Error Branch — Do NOT Catch
Error and its subclasses represent serious system failures that are beyond the control of your program. These indicate problems with the JVM itself or the underlying hardware/OS environment. You should never try to catch or recover from these.
Analogy The Earthquake Analogy
We can handle problems inside our car or building. If the engine overheats, pull over. If a pipe bursts, call a plumber. But if there's an earthquake — that's out of our scope. The entire ground beneath us is shaking. There's nothing we can fix about the earth's tectonic plates.
Similarly, if the JVM goes down, everything goes down. Your Java program cannot fix the JVM. An OutOfMemoryError means the JVM has exhausted all available memory — your program can't magically create more RAM. A StackOverflowError means infinite recursion has consumed the entire call stack — there's no stack space left to even run your catch block properly.
That's why Error is on the left branch of our tree, completely separate from Exception. They are fundamentally different beasts.
Error = do NOT catch. These are system-level catastrophes.
Exception = CAN handle. These are problems your program can recover from.
4 Summary
- Throwable is the root of the entire exception hierarchy — everything that can be thrown extends it.
- Error represents catastrophic system failures (like OutOfMemoryError) — do NOT catch these.
- Exception represents recoverable problems — this is where your try-catch blocks focus.
- RuntimeException is a special branch under Exception — we will learn the difference between these two branches later when we create our own custom exceptions.
In the next lesson: how exceptions travel through the call stack — exception propagation.