Q21: How is the Java Exception Class Hierarchy structured (Checked vs Unchecked)?
Throwable is the root class, branching into Error and Exception:
- Checked Exceptions: Subclasses of
Exception(excludingRuntimeException). The compiler forces developers to catch or declare them (IOException,SQLException). Represents recoverable conditions. - Unchecked Exceptions: Subclasses of
RuntimeException(NullPointerException,IllegalArgumentException). Represents programming bugs. Error: Serious system failures (OutOfMemoryError,StackOverflowError). Applications should not attempt recovery.
Throwable Class Hierarchy Structure
Key Takeaways
- Checked = Forced by compiler (
Exceptionsubclasses). Unchecked = Runtime errors (RuntimeExceptionsubclasses).
Knowledge Check
Which of the following exceptions is a CHECKED exception enforced by the Java compiler?