- 2072 Asoj · 5 marks
Exception class hierarchy from Throwable
Short answer
Throwable is the root; its subclasses are Error (unchecked, e.g., OutOfMemoryError, StackOverflowError) and Exception (checked). Exception includes IOException, SQLException, and RuntimeException (unchecked) with subclasses like NullPointerException, ArithmeticException, IndexOutOfBoundsException, etc. Catch blocks should order most specific first.
Draw an exception class hierarchy to present the errors and exceptions derived from the Throwable class.
In Java, Throwable is the root class of everything that can be thrown. It has two direct subclasses: Error and Exception.
Throwable
|
+-- Error (unchecked)
| +-- VirtualMachineError
| | +-- OutOfMemoryError
| | +-- StackOverflowError
| +-- AssertionError
| +-- LinkageError
|
+-- Exception (checked)
+-- IOException
| +-- FileNotFoundException
| +-- EOFException
+-- SQLException
+-- ReflectiveOperationException
| +-- ClassNotFoundException
+-- InterruptedException
+-- RuntimeException (unchecked)
+-- ArithmeticException
+-- NullPointerException
+-- ClassCastException
+-- IndexOutOfBoundsException
| +-- ArrayIndexOutOfBoundsException
+-- IllegalArgumentException
+-- NumberFormatException
Other subclasses of Exception include CloneNotSupportedException and TimeoutException.
Explanation
- Throwable: provides
getMessage()andprintStackTrace(); only its objects can be thrown or caught. - Error: serious problems in the JVM or system that an application should not try to handle (
OutOfMemoryError,StackOverflowError). Unchecked. - Exception: conditions that a program can reasonably catch.
- Checked exceptions (
IOException,SQLException,ClassNotFoundException): the compiler requirestry/catchor athrowsclause. - Unchecked (runtime) exceptions (
RuntimeExceptionand its subclasses:ArithmeticException,NullPointerException,ArrayIndexOutOfBoundsException): caused by programming errors; handling them is optional.
- Checked exceptions (
Order of catch blocks: the specific subclass comes first, then its superclass.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Access overridden members from derived class · Object Oriented Programming, chapter 6 · asked 2×
- Stream class hierarchy · Object Oriented Programming, chapter 8 · asked 4×
- Date of birth validation with exceptions · Object Oriented Programming, chapter 10
- Manager derived from person and employee · Object Oriented Programming, chapter 6
All Object Oriented Analysis and Design chapter 4 questions →