⚡ Section 7 · 29 questions
Exceptions
29 interview questions and answers in the Exceptions section.
Questions in this section
- What is the difference between checked and unchecked exceptions
- What is a checked exception and when to use it
- What is an unchecked exception (Runtime Exception)
- Which exceptions must be handled
- What is at the top of the exception hierarchy
- What is Throwable
- What is the difference between Error and Exception
- Is the execution of a finally block guaranteed
- What is try-with-resources
- What are the requirements for resources in try-with-resources
- What is the AutoCloseable interface
- What is the difference between AutoCloseable and Closeable
- Can you create custom exceptions
- When should you create your own exceptions
- What is better extend Exception or RuntimeException
- What is a stack trace
- What does the printStackTrace() method do
- How to properly log exceptions
- What is exception wrapping
- Why you should not swallow exceptions
- What does the throws keyword do
- Can you throw a checked exception without declaring throws
- What happens if an exception occurs in finally block
- What are suppressed exceptions
- Can you have multiple catch blocks for a single try
- What is multi-catch (catching multiple exceptions)
- What is the order of catch blocks
- Can you rethrow an exception
- 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
🗺️ 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) │
└──────────────────────────────────────────┘
🎯 Recommended Learning Path
🟢 Junior Level (Weeks 1–2)
- Hierarchy: What is at the top of the exception hierarchy, What is the difference between Error and Exception.
- Checked vs. Unchecked: What is the difference between checked and unchecked exceptions, Which exceptions must be handled.
- 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.
- Basic Logging: What does the printStackTrace() method do.
🟡 Middle Level (Weeks 3–4)
- 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.
- Domain Modeling: Can you create custom exceptions, When should you create your own exceptions, What is better: extend Exception or RuntimeException.
- 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)
- JVM Mechanics & Performance: Stack trace generation cost (
fillInStack()), creating stackless exceptions for high-frequency control flow. - Compiler Secrets: Sneaky Throws via generic type erasure (
@SneakyThrows/Lombok), precise rethrow bytecode analysis. - Suppression & Concurrency: Suppressed exceptions mechanism in Try-With-Resources and Structured Concurrency (
StructuredTaskScope). - Resilience & Production Fault Tolerance: Circuit Breaker exception classification, Spring
@ControllerAdvice+ RFC 9457ProblemDetail.
📝 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.