Veda Bites are swipeable micro-lessons — each one teaches exactly one
idea. Here's a taste from this kit; the app has the full deck.
💡 Key Idea
What is an Exception?
An unexpected event during program execution.
An exception is an event that disrupts the normal flow of a program's instructions. In Java, exceptions are objects that describe an error or unexpected condition. They can arise from user input, hardware failures, or programming bugs. Handling exceptions allows the program to continue or fail gracefully.
↳ Exceptions are runtime disruptions that can be managed to keep programs stable.
📖 Definition
Exception Hierarchy
All exceptions inherit from Throwable.
The root of the exception hierarchy is the Throwable class. It has two main subclasses: Exception (for recoverable conditions) and Error (for serious problems like `OutOfMemoryError`). `Exception` is further divided into checked and unchecked exceptions.
↳ Understanding the hierarchy helps in catching the right exception type.
💡 Key Idea
Checked vs Unchecked Exceptions
Compiler enforces checked, not unchecked.
Checked exceptions are checked at compile time; the compiler forces you to handle them (e.g., `IOException`). Unchecked exceptions occur at runtime and are not checked by the compiler (e.g., `ArithmeticException`). They are subclasses of `RuntimeException`.
↳ Checked exceptions demand handling; unchecked exceptions are optional to handle.