Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Exception Handling & Custom Exceptions

Explain checked versus unchecked exceptions and the modern argument for preferring unchecked in many designs.

Level II · JuniorException Handling & Custom Exceptions
Short answer

Checked exceptions (subclasses of Exception, not RuntimeException) must be declared or handled and are meant for recoverable conditions; unchecked (RuntimeException) signal programming errors or unrecoverable states and need no declaration.

Explanation

Many modern frameworks (Spring) favor unchecked exceptions because checked exceptions force boilerplate, leak across abstraction layers, and don't compose with lambdas/streams (functional interfaces don't declare them). The trade-off is checked exceptions document recoverable failures at compile time, which is genuinely valuable for true business-recoverable cases like IO.

Common mistakes
  • Catching Exception everywhere and ignoring it.
  • Wrapping every checked exception in RuntimeException without context.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Exception Handling & Custom Exceptions.

Practise free

More on Exception Handling & Custom Exceptions