Java Exception Handling Interview Questions 2026: 26 Q&A
26 Java exception handling interview questions for 2026 with full answers, checked vs unchecked, try-with-resources, custom exceptions and predict-the-output snippets. Candidate-reported service and product company favourites.
on this page§ 09
Last Updated: June 2026 | Level: Freshers to Mid-Level | Read Time: ~15 min
Exception handling is a guaranteed topic in Java interviews. Candidates report that interviewers love the checked-versus-unchecked distinction, the finally plus return trap, and custom exception design. This guide covers 26 questions with full answers, runnable code, and the gotchas interviewers use to separate rote learners from people who understand control flow. Behaviour reflects the official Oracle Java tutorials; confirm spec-level details against JLS chapter 11.
Pair this with Java Interview Questions 2026 and Java OOPs Interview Questions 2026.
Table of Contents
- Fundamentals (Q1 to Q9)
- Control Flow and finally (Q10 to Q16)
- Custom and Advanced (Q17 to Q22)
- Best Practices (Q23 to Q26)
- Predict the Output
- Exception Hierarchy Table
- Frequently Asked Questions
Fundamentals
Q1. What is an exception in Java? Easy
Q2. What is the difference between an error and an exception? Easy
Q3. What is the difference between checked and unchecked exceptions? Medium
| Type | Examples | Compile-time check |
|---|---|---|
| Checked | IOException, SQLException | Yes |
| Unchecked | NullPointerException, ArrayIndexOutOfBoundsException | No |
| Error | OutOfMemoryError, StackOverflowError | No |
Q4. What is the exception hierarchy in Java? Easy
Q5. What is the difference between throw and throws? Easy
Q6. Can a try block exist without a catch? Medium
Q7. Can you catch multiple exceptions in one catch? Medium
try { risky(); }
catch (IOException | SQLException e) { log(e); }
Q8. What is exception chaining? Medium
catch (SQLException e) {
throw new DataAccessException("query failed", e); // preserves cause
}
Q9. What happens if an exception is not caught anywhere? Medium
Control Flow and finally
Q10. What is the finally block and when does it run? Easy
Q11. Does finally run if there is a return in try? Hard
int test() {
try { return 1; }
finally { return 2; } // overrides; method returns 2
}
Q12. What happens if both try and finally throw exceptions? Hard
Q13. What is try-with-resources? Medium
try (BufferedReader br = new BufferedReader(new FileReader("f.txt"))) {
return br.readLine();
} // br.close() called automatically
Q14. What is a suppressed exception? Hard
Q15. Can you have nested try blocks? Medium
Q16. What is the order of catch blocks? Medium
Custom and Advanced
Q17. How do you create a custom exception? Medium
class InsufficientFundsException extends RuntimeException {
InsufficientFundsException(String msg) { super(msg); }
}
Q18. When should a custom exception be checked vs unchecked? Hard
Q19. What is the difference between final, finally, and finalize? Medium
Q20. Can a constructor throw an exception? Medium
Q21. What happens to an exception thrown in a finally during stack unwinding? Hard
Q22. How does exception handling work with method overriding? Hard
Best Practices
Q23. Why is catching Exception or Throwable broadly bad? Medium
Q24. Why should you not use exceptions for control flow? Medium
Q25. What should you log when handling an exception? Easy
Q26. What is the cost of throwing an exception? Hard
Predict the Output
Snippet 1
public static int f() {
try { return 1; }
finally { System.out.println("finally"); }
}
System.out.println(f());
Output:
finally
1
Why: finally runs after the return value (1) is computed but before the method returns, so "finally" prints first, then the returned 1.
Snippet 2
try {
int[] a = new int[2];
a[5] = 1;
System.out.println("after");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("caught");
} finally {
System.out.println("done");
}
Output:
caught
done
Why: The out-of-bounds write throws before "after" prints, control jumps to the matching catch, then finally always runs.
Snippet 3
public static int g() {
try { return 1; }
finally { return 2; }
}
System.out.println(g());
Output:
2
Why: A return inside finally overrides the try's return. The method returns 2, the value 1 is discarded. This is the classic trap question.
Exception Hierarchy Table
| Level | Class | Recoverable | Compile-checked |
|---|---|---|---|
| Root | Throwable | n/a | no |
| Serious | Error | no | no |
| General | Exception | yes | yes (most) |
| Runtime | RuntimeException | sometimes | no |
Frequently Asked Questions
What is the most asked exception handling question in 2026?
Candidates report that the difference between checked and unchecked exceptions, and the behaviour of finally when try has a return, are the two most repeated questions in Java rounds.
Is try-with-resources important for interviews?
Yes. Interviewers expect you to use try-with-resources for any closeable resource and to explain that it auto-closes in reverse order of declaration and suppresses secondary exceptions rather than masking the primary one.
Can finally override a return value?
Yes, and it is a known trap. A return inside finally overrides any return or exception from try or catch, which is exactly why returning from finally is considered bad practice.
What is the difference between final, finally, and finalize?
final is a modifier for constants and non-overridable members, finally is the always-run block after try, and finalize is a deprecated pre-GC hook you should never rely on. Interviewers ask this to test attention to detail.
Should custom exceptions be checked or unchecked?
Make it checked when the caller can recover and you want to force handling; make it unchecked for programming errors or unrecoverable conditions. Modern codebases often lean unchecked to keep method signatures clean.
Related Articles
- Java Interview Questions 2026, the master 50-question set
- Java OOPs Interview Questions 2026, OOP foundations
- Java Multithreading Interview Questions 2026, concurrency rounds
- Java String Interview Questions 2026, strings and immutability
Confirm any spec-level exception semantics against the official JLS and Oracle tutorials before your interview. This guide reflects candidate-reported patterns and public preparation resources as of June 2026.
Sources and review notesreviewed 8 Jun 2026
Official notices, candidate reports, offer documents, and editorial practice questions carry different confidence levels. The visible source list lets you inspect the evidence instead of relying on a blanket verification badge.
topic cluster
More resources in Interview Questions
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.
paid contributor programme
Sat this this year? Share your story, earn ₹500.
First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story with byline.
Submit your story →ready to practice?
Take a free timed mock test
Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.