⚡ Section 7 · 29 questions

Exceptions

29 interview questions and answers in the Exceptions section.

Questions in this section

  1. What is the difference between checked and unchecked exceptions
  2. What is a checked exception and when to use it
  3. What is an unchecked exception (Runtime Exception)
  4. Which exceptions must be handled
  5. What is at the top of the exception hierarchy
  6. What is Throwable
  7. What is the difference between Error and Exception
  8. Is the execution of a finally block guaranteed
  9. What is try-with-resources
  10. What are the requirements for resources in try-with-resources
  11. What is the AutoCloseable interface
  12. What is the difference between AutoCloseable and Closeable
  13. Can you create custom exceptions
  14. When should you create your own exceptions
  15. What is better extend Exception or RuntimeException
  16. What is a stack trace
  17. What does the printStackTrace() method do
  18. How to properly log exceptions
  19. What is exception wrapping
  20. Why you should not swallow exceptions
  21. What does the throws keyword do
  22. Can you throw a checked exception without declaring throws
  23. What happens if an exception occurs in finally block
  24. What are suppressed exceptions
  25. Can you have multiple catch blocks for a single try
  26. What is multi-catch (catching multiple exceptions)
  27. What is the order of catch blocks
  28. Can you rethrow an exception
  29. What is exception chaining

Study navigator

29 curated questions for mastering Java Exception architecture, Throwable class hierarchy, memory mechanics, error recovery patterns, and modern logging across Junior 🟢, Middle 🟡, and Senior 🔴 Java Developer technical interviews.


📋 All Questions

# Question Difficulty
01 What is the difference between checked and unchecked exceptions ⭐⭐
02 What is a checked exception and when to use it ⭐⭐
03 What is an unchecked exception (Runtime Exception) ⭐⭐
04 Which exceptions must be handled ⭐
05 What is at the top of the exception hierarchy ⭐
06 What is Throwable ⭐⭐
07 What is the difference between Error and Exception ⭐⭐
08 Is the execution of a finally block guaranteed ⭐⭐
09 What is try-with-resources ⭐⭐
10 What are the requirements for resources in try-with-resources ⭐⭐
11 What is the AutoCloseable interface ⭐⭐
12 What is the difference between AutoCloseable and Closeable ⭐⭐
13 Can you create custom exceptions ⭐
14 When should you create your own exceptions ⭐⭐
15 What is better: extend Exception or RuntimeException ⭐⭐
16 What is a stack trace ⭐⭐
17 What does the printStackTrace() method do ⭐
18 How to properly log exceptions ⭐⭐
19 What is exception wrapping ⭐⭐
20 Why you should not swallow exceptions ⭐⭐
21 What does the throws keyword do ⭐
22 Can you throw a checked exception without declaring throws ⭐⭐⭐
23 What happens if an exception occurs in finally block ⭐⭐⭐
24 What are suppressed exceptions ⭐⭐⭐
25 Can you have multiple catch blocks for a single try ⭐
26 What is multi-catch (catching multiple exceptions) ⭐⭐
27 What is the order of catch blocks ⭐⭐
28 Can you rethrow an exception ⭐⭐
29 What is exception chaining ⭐⭐

🗺️ Topic Dependency Map

                    ┌──────────────────────────────────────────┐
                    │   HIERARCHY & THROWABLE (05-07)          │
                    │   05. Top of Hierarchy (Throwable)       │
                    │   06. Throwable Deep Dive & fillInStack  │
                    │   07. Error vs Exception                 │
                    └──────────────────┬───────────────────────┘
                                       │
            ┌──────────────────────────┼──────────────────────────┐
            ▼                          ▼                          ▼
    ┌───────────────┐        ┌───────────────┐        ┌────────────────────┐
    │ CHECKED vs    │        │ RESOURCE MGMT │        │ CUSTOM EXCEPTIONS  │
    │ UNCHECKED     │        │ (08-12)       │        │ (13-15)            │
    │ (01-04)       │        │ 08. finally   │        │ 13. Custom Allowed │
    │ 01. Checked vs│        │ 09. try-w-res │        │ 14. When to Create │
    │ 02. Checked   │        │ 10. Reqmts    │        │ 15. Exception vs   │
    │ 03. Unchecked │        │ 11. AutoClose │        │     RuntimeException
    │ 04. Required  │        │ 12. Auto vs Cl│        └────────┬───────────┘
    └───────┬───────┘        └───────┬───────┘                 │
            │                        │                         │
            └────────────────────────┼─────────────────────────┘
                                     │
                                     ▼
                    ┌──────────────────────────────────────────┐
                    │   STACK TRACES & LOGGING (16-20)         │
                    │   16. Stack Trace Structure & Overhead   │
                    │   17. printStackTrace() Antipattern      │
                    │   18. Production SLF4J / Logback Logging │
                    │   19. Exception Wrapping & Root Causes   │
                    │   20. Exception Swallowing Pitfalls      │
                    └──────────────────┬───────────────────────┘
                                       │
                                       ▼
                    ┌──────────────────────────────────────────┐
                    │   ADVANCED COMPILER & RUNTIME (21-29)    │
                    │   21. throws keyword                     │
                    │   22. Sneaky Throws (Generics / Unsafe)  │
                    │   23. finally exception mask trap        │
                    │   24. Suppressed Exceptions & TWR        │
                    │   25. Multiple catch                     │
                    │   26. Multi-catch & final union types    │
                    │   27. Catch ordering rule (narrow->wide) │
                    │   28. Rethrowing (precise rethrow)       │
                    │   29. Exception Chaining (initCause)     │
                    └──────────────────────────────────────────┘

🟢 Junior Level (Weeks 1–2)

  1. Hierarchy: What is at the top of the exception hierarchy, What is the difference between Error and Exception.
  2. Checked vs. Unchecked: What is the difference between checked and unchecked exceptions, Which exceptions must be handled.
  3. Basic Flow: What does the throws keyword do, Can you have multiple catch blocks for a single try, What is the order of catch blocks.
  4. Basic Logging: What does the printStackTrace() method do.

🟡 Middle Level (Weeks 3–4)

  1. Resource Management: Is the execution of a finally block guaranteed, What is try-with-resources, What is the AutoCloseable interface, What is the difference between AutoCloseable and Closeable.
  2. Domain Modeling: Can you create custom exceptions, When should you create your own exceptions, What is better: extend Exception or RuntimeException.
  3. Enterprise Handling: How to properly log exceptions, What is exception wrapping, Why you should not swallow exceptions, What is multi-catch (catching multiple exceptions), What is exception chaining.

🔴 Senior Level (Weeks 5–6)

  1. JVM Mechanics & Performance: Stack trace generation cost (fillInStack()), creating stackless exceptions for high-frequency control flow.
  2. Compiler Secrets: Sneaky Throws via generic type erasure (@SneakyThrows / Lombok), precise rethrow bytecode analysis.
  3. Suppression & Concurrency: Suppressed exceptions mechanism in Try-With-Resources and Structured Concurrency (StructuredTaskScope).
  4. Resilience & Production Fault Tolerance: Circuit Breaker exception classification, Spring @ControllerAdvice + RFC 9457 ProblemDetail.

📝 4-Level File Structure Standards

Every topic file strictly implements:

  • 🟢 Junior Level — Core language definitions, compiler rules, standard syntax examples.
  • 🟡 Middle Level — Deep dive into runtime semantics, resource lifecycle, logging frameworks (SLF4J/Logback), clean design patterns.
  • 🔴 Senior Level — Bytecode mechanics, JVM stack trace performance overhead, sneaky throws, suppressed exceptions, fault tolerance.
  • 🎯 Interview Cheat Sheet — High-yield bullets, follow-up questions, red flags, and cross-section links.