Skip to main content

4.1 The Throwable Class Hierarchy

← Back to Chapter 4: Exception Handling

All exceptional situations in Java inherit from a single superclass: java.lang.Throwable.


What is Exception Handling?​

An exception is an unexpected problem that happens while a program is running.

Exception handling means:

"When something goes wrong, handle the problem properly instead of allowing the application to crash unexpectedly."

Exception Hierarchy​

Throwable is the parent of Error and Exception.

┌─────────────────────────┐
│ java.lang.Throwable │
└────────────┬────────────┘
│
┌───────────────────────┴───────────────────────┐
▼ ▼
┌────────────────────────┐ ┌────────────────────────┐
│ java.lang.Error │ │ java.lang.Exception │
│ (Unrecoverable System) │ │ (Application Recovery) │
└───────────┬────────────┘ └───────────┬────────────┘
│ │
┌───────┴────────┐ ┌────────────────┴────────────────┐
▼ ▼ ▼ ▼
OutOfMemoryError StackOverflowError RuntimeException Checked Exceptions
(Unchecked) (Checked at compile time)
• NullPointerException • IOException
• ArithmeticException • SQLException
• IllegalArgumentException • ClassNotFoundException

2. Error vs Exception​

Dimensionjava.lang.Errorjava.lang.Exception
OriginFatal JVM or hardware-level failuresApplication logic, network, or external IO failures
RecoveryUnrecoverable: Application should terminateRecoverable: Application should catch, log, and handle
ExamplesOutOfMemoryError, StackOverflowError, NoClassDefFoundErrorFileNotFoundException, IllegalArgumentException
HandlingNever catch Error in production codeHandled using try-catch blocks or propagated via throws
Never Catch java.lang.Throwable Blindly

Catching Throwable will intercept fatal JVM errors like OutOfMemoryError or ThreadDeath, preventing the JVM from shutting down cleanly or triggering diagnostic dumps.