Junior — Middle
How is the hierarchy of exceptions structured in a programming language?
sobes.tech AI
Answer from AI
In Java, the hierarchy of exceptions is organized around the base class Throwable. From it, two main subclasses are inherited:
Error— errors that are usually not handled by the application (e.g.,OutOfMemoryError).Exception— exceptions that can and should be handled.
Further, Exception is divided into:
- Checked exceptions — require mandatory handling or declaration in the method (e.g.,
IOException). - Unchecked exceptions, which inherit from
RuntimeException(e.g.,NullPointerException).
Thus, the structure looks like this:
Throwable
├── Error
└── Exception
├── RuntimeException
└── (other checked exceptions)
This allows the compiler and developers to distinguish between exception types and handle them correctly.