Exception Handling Interview Questions
Checked vs unchecked exceptions, try-catch-finally, and custom exception patterns.
- 20Questions with answers
- 3Difficulty levels
Questions (20)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
What is an exception in Java?
An exception is an event that disrupts the normal flow of program execution and occurs during runtime.
What is the difference between Error and Exception?
Errors represent serious system-level problems that applications usually cannot recover from, while Exceptions represent conditions that applications can handle.
What are the types of exceptions in Java?
Exceptions are categorized as checked exceptions and unchecked exceptions.
What is a checked exception?
A checked exception is verified by the compiler and must be either handled or declared using the throws keyword.
What is an unchecked exception?
An unchecked exception occurs at runtime and does not require explicit handling by the compiler.
What is the difference between throw and throws?
throw is used to explicitly throw an exception, while throws is used in method signatures to declare exceptions that may occur.
What is a try-catch block?
A try-catch block is used to handle exceptions by enclosing risky code in a try block and handling errors in a catch block.
What is the purpose of the finally block?
The finally block contains code that executes regardless of whether an exception occurs, typically used for resource cleanup.
Can the finally block be skipped?
Normally no, but it may not execute if the JVM terminates unexpectedly using System.exit() or due to a fatal system error.
What is a custom exception?
A custom exception is a user-defined exception class that extends Exception or RuntimeException to represent application-specific errors.
What is try-with-resources?
Try-with-resources automatically closes resources that implement AutoCloseable, reducing boilerplate code and resource leaks.
What happens if an exception is not handled?
The exception propagates up the call stack. If no handler is found, the JVM terminates the program and prints a stack trace.
What is the difference between final, finally, and finalize?
final restricts modification, finally is used for cleanup in exception handling, and finalize was a garbage collection hook that is deprecated.
What is exception propagation?
Exception propagation is the process of passing an exception from one method to its caller until it is handled.
What are some best practices for exception handling?
Handle specific exceptions, avoid empty catch blocks, use custom exceptions when appropriate, log exceptions properly, and clean up resources using try-with-resources.
Which Java language or JDK features are essential when discussing Exception Handling?
Name concrete APIs (collections, concurrency, streams, annotations) tied to Exception Handling. Interviewers want syntax-level clarity plus when you would reach for each feature in production.
How does exception handling typically work around Exception Handling in Java?
Prefer specific checked/unchecked exceptions, wrap lower-level failures with context, and avoid empty catch blocks. For Exception Handling, decide what is recoverable vs fatal to the request thread.
What unit-testing approach would you use for Exception Handling?
JUnit 5 with Arrange-Act-Assert, Mockito for collaborators, and parameterized tests for edge cases. Keep Exception Handling logic pure where possible so tests stay fast.
How do equals/hashCode or identity rules affect Exception Handling?
Incorrect equals/hashCode break HashMap/HashSet behavior. If Exception Handling stores objects in collections, explain the contract and mutability pitfalls.
What memory or GC concern should juniors watch with Exception Handling?
Retain only needed references, prefer streaming for large datasets, and avoid accidental caches. Relate leaks or GC pressure to a concrete Exception Handling scenario.
Practice with AI mock interviews
Run Java mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required