Java Exceptions
Fast recall
Quick revision
Core answer
Throwable object. throw transfers control out of the current path, Java searches outward for a compatible catch, and finally or try-with-resources performs defined cleanup on the way out. The mechanism lets failures cross method boundaries without return-code checks after every call; checked exceptions additionally use catch-or-declare at compile time.Whether you understand the exception hierarchy (Throwable, Error, Exception, RuntimeException) and the distinction between checked and unchecked exceptions.
Catching generic Exception or Throwable to swallow errors, or confusing RuntimeException (unchecked) with checked exceptions like IOException.
Explain the design philosophy behind checked exceptions, when to create custom exceptions, and the cost of exception stack traces in performance-critical code.
Interview-ready guide
Interview answer
Java exceptions provide a separate control path for an operation that cannot complete normally. A Throwable is thrown, normal execution in that path stops, and Java searches outward for a compatible catch while leaving call frames. Finally blocks and try-with-resources perform cleanup according to their rules.
This lets a low-level method report failure to a caller that can recover, translate, or map it at a boundary without every intermediate method returning an error code. Checked exceptions also require catch-or-declare at compile time; unchecked exceptions can propagate without being declared.
Java Exceptions
Direct Answer
Java exceptions represent a failure or unusual completion as a Throwable object. throw transfers control out of the current path, Java searches outward for a compatible catch, and finally or try-with-resources performs defined cleanup on the way out. The mechanism lets failures cross method boundaries without return-code checks after every call; checked exceptions additionally use catch-or-declare at compile time.
Common Mistakes & Pitfalls
Catching generic Exception or Throwable to swallow errors, or confusing RuntimeException (unchecked) with checked exceptions like IOException.
Check your understanding
Answer these without looking back at the article.
- What is the difference between throw and throws in Java?
- When should you create a custom exception class instead of using an existing one?
- What happens if an exception is thrown inside a finally block?
- How does try-with-resources improve on traditional try-finally for resource management?
- Why do some frameworks like Spring convert checked exceptions to unchecked ones?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.