← Back to libraryQuestion 47 of 273
JavaAdvanced

Checked vs Unchecked Exception Design

📖 Detailed Explanation:

Design rule: Use Checked exceptions for conditions the caller can reasonably recover from (FileNotFoundException, SQLException). Use Unchecked (Runtime) exceptions for programming errors (NullPointerException, ArrayIndexOutOfBoundsException). Throwable is the base class; Exception and Error extend it.

🎯 Scenario-Based Interview Question:

A library you're writing encounters an invalid configuration file. Should you throw a checked or unchecked exception? Justify your choice.

💡 Interview Focus:

Interviewers look for your judgment in designing clean, maintainable error handling logic. Think about what the caller can DO with the exception.