What is the exception class hierarchy in Java (Throwable, Error, Exception)?
6 minbeginnerthrowableerrorexceptionhierarchy
Quick Answer
Throwable is the root of everything catchable. It splits into Error (serious, typically unrecoverable JVM/system-level problems like OutOfMemoryError or StackOverflowError, not meant to be caught) and Exception (application-level problems). Exception further splits into RuntimeException (unchecked) and everything else (checked exceptions like IOException).
Detailed Answer
Throwable
├── Error (unchecked — serious, usually unrecoverable)
│ ├── OutOfMemoryError
│ ├── StackOverflowError
│ └── ...
└── Exception
├── RuntimeException (unchecked — programming errors)
│ ├── NullPointerException
│ ├── IllegalArgumentException
│ ├── IndexOutOfBoundsException
│ └── ...
└── (everything else) (checked — recoverable conditions)
├── IOException
├── SQLException
└── ...
Throwable: the root of the entire hierarchy — onlyThrowable(and its subclasses) can be passed tothrowor caught bycatch.Error: represents serious problems typically caused by the environment/JVM itself rather than application logic —OutOfMemoryError,StackOverflowError,NoClassDefFoundError. Applications generally shouldn't try to catch or recover from these; they usually indicate the JVM is in an unstable state.Exception: represents application-level conditions. Splits further intoRuntimeException(unchecked — see the checked/unchecked question) and all other checked exceptions.
Common gotcha: catch (Exception e) does not catch Errors (they're siblings under Throwable, not related by inheritance) — you'd need catch (Throwable t) for that, which is almost always a code smell since it also swallows things like OutOfMemoryError that you generally shouldn't attempt to handle.