← Back to libraryQuestion 13 of 273
JavaIntermediate

Exception Handling (Checked vs Unchecked)

📖 Detailed Explanation:

Exceptions handle runtime errors. Checked exceptions (like SQLException, IOException) are checked at compile-time—the compiler FORCES you to either handle them or declare them. Unchecked exceptions (like NullPointerException, IndexOutOfBoundsException) are checked at runtime and usually represent logical bugs or programming errors.

🌍 Real-World Example:

Checked: Your doctor requires you to get vaccinated before traveling (compiler enforces it). Unchecked: You might forget your umbrella on a rainy day (your mistake, compiler doesn't catch it).

🎯 Scenario-Based Interview Question:

Why should you NEVER catch the 'Error' class in Java? Provide an example.