Skip to content
Sharp

Exceptions interview questions

Checked vs unchecked, try-with-resources, finally.

160 questions with answers and explanations · 158 flashcards

Key ideas

  • Checked exceptions (IOException) must be caught or declared; unchecked (RuntimeException and subclasses) needn't be.
  • try-with-resources closes resources automatically, in reverse order of declaration; exceptions from close() are attached as *suppressed*.
  • finally runs on normal exit, return or exception, but not after System.exit().

Questions (page 4 of 4)

  1. When wrapping exceptions, which practice helps ensure observability?Multiple choiceMedium
  2. Why does Java use exceptions instead of error codes?Multiple choiceEasy
  3. Which design principle is violated if exceptions are used to handle expected conditions?Multiple choiceHard
  4. Which approach is the safest default for handling exceptions in library code?Multiple choiceMedium
  5. How can you ensure resources are released after usage?Multiple choiceEasy
  6. Why does throwing an IllegalArgumentException in a method help in practice?Multiple choiceMedium
  7. In a complex e-commerce system, some errors should be logged and ignored. Which exception type suits this pattern?Multiple choiceHard
  8. When is an unchecked exception often the clearer choice?Multiple choiceMedium
  9. Why do teams use checked exceptions for API design in production code?Multiple choiceMedium
  10. Which Java feature allows you to handle multiple exception types in a single catch block?Multiple choiceMedium