Java

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.

Question 1
Interview Beginner
Question

What is an exception in Java?

Answer:

An exception is an event that disrupts the normal flow of program execution and occurs during runtime.

Question 2
Interview Beginner
Question

What is the difference between Error and Exception?

Answer:

Errors represent serious system-level problems that applications usually cannot recover from, while Exceptions represent conditions that applications can handle.

Question 3
Interview Beginner
Question

What are the types of exceptions in Java?

Answer:

Exceptions are categorized as checked exceptions and unchecked exceptions.

Question 4
Interview Beginner
Question

What is a checked exception?

Answer:

A checked exception is verified by the compiler and must be either handled or declared using the throws keyword.

Question 5
Interview Beginner
Question

What is an unchecked exception?

Answer:

An unchecked exception occurs at runtime and does not require explicit handling by the compiler.

Question 6
Interview Beginner
Question

What is the difference between throw and throws?

Answer:

throw is used to explicitly throw an exception, while throws is used in method signatures to declare exceptions that may occur.

Question 7
Interview Beginner
Question

What is a try-catch block?

Answer:

A try-catch block is used to handle exceptions by enclosing risky code in a try block and handling errors in a catch block.

Question 8
Interview Intermediate
Question

What is the purpose of the finally block?

Answer:

The finally block contains code that executes regardless of whether an exception occurs, typically used for resource cleanup.

Question 9
Interview Intermediate
Question

Can the finally block be skipped?

Answer:

Normally no, but it may not execute if the JVM terminates unexpectedly using System.exit() or due to a fatal system error.

Question 10
Interview Intermediate
Question

What is a custom exception?

Answer:

A custom exception is a user-defined exception class that extends Exception or RuntimeException to represent application-specific errors.

Question 11
Interview Intermediate
Question

What is try-with-resources?

Answer:

Try-with-resources automatically closes resources that implement AutoCloseable, reducing boilerplate code and resource leaks.

Question 12
Interview Intermediate
Question

What happens if an exception is not handled?

Answer:

The exception propagates up the call stack. If no handler is found, the JVM terminates the program and prints a stack trace.

Question 13
Interview Intermediate
Question

What is the difference between final, finally, and finalize?

Answer:

final restricts modification, finally is used for cleanup in exception handling, and finalize was a garbage collection hook that is deprecated.

Question 14
Interview Intermediate
Question

What is exception propagation?

Answer:

Exception propagation is the process of passing an exception from one method to its caller until it is handled.

Question 15
Interview Advanced
Question

What are some best practices for exception handling?

Answer:

Handle specific exceptions, avoid empty catch blocks, use custom exceptions when appropriate, log exceptions properly, and clean up resources using try-with-resources.

Question 16
Interview Advanced
Question

Which Java language or JDK features are essential when discussing Exception Handling?

Answer:

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.

Question 17
Interview Advanced
Question

How does exception handling typically work around Exception Handling in Java?

Answer:

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.

Question 18
Interview Advanced
Question

What unit-testing approach would you use for Exception Handling?

Answer:

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.

Question 19
Interview Advanced
Question

How do equals/hashCode or identity rules affect Exception Handling?

Answer:

Incorrect equals/hashCode break HashMap/HashSet behavior. If Exception Handling stores objects in collections, explain the contract and mutability pitfalls.

Question 20
Interview Advanced
Question

What memory or GC concern should juniors watch with Exception Handling?

Answer:

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