Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Java
Javamedium

Checked vs unchecked exceptions — what’s the difference?

Tags
#exceptions#checked#runtimeexception
Back to categoryPractice quiz

Answer

Checked exceptions must be declared or handled at compile time (they extend `Exception` but not `RuntimeException`). Unchecked exceptions (`RuntimeException`) don’t require it and usually indicate programming errors or invalid state.

Advanced answer

Deep dive

Checked exceptions are part of the method’s contract: callers must handle them (try/catch) or declare them (throws). Unchecked exceptions are not enforced by the compiler.

Rule of thumb:

  • Checked: recoverable situations the caller can realistically handle (e.g., IO, missing file) — though this is debated in modern Java.
  • Unchecked: programmer errors / invariant violations (NPE, IllegalArgumentException, IllegalStateException).

Practical guidance

  • Avoid “throws Exception” (it hides the real contract).
  • Wrap low-level exceptions at module boundaries with context (custom exceptions).
  • Don’t use exceptions for normal control flow.

Common pitfalls

  • Overusing checked exceptions leading to noisy boilerplate.
  • Swallowing exceptions (catch and do nothing).
  • Turning everything into RuntimeException without adding context/logging.

Related questions

Java
Try-with-resources: what does it require and why is it useful?
#java#exceptions#resources
Kotlin
Coroutine exceptions: how do they propagate and when to use `CoroutineExceptionHandler`?
#kotlin#coroutines#exceptions