Interview replay

Full round replay — checked vs unchecked

10 minintermediate08 yrs

Timed verbal replay with pass/fail criteria per follow-up.

How to run this

Answer out loud, timed. Do not read the entry first. Then compare against "The Answer" and "Interviewer's Next Move" and mark yourself.

The opener

What is the difference between checked and unchecked exceptions?

Budget: 45 seconds. Going long here is itself a fail signal.

Follow-ups

  1. 1. “What single fact decides whether an exception is checked?

    Testing: Mechanism, not examples.

    Scoring

    Pass: Position in the hierarchy: under RuntimeException (or Error) it is unchecked, anything else under Exception is checked. No keyword, no annotation.

    Fail: Only lists examples, or thinks there is a modifier involved.

  2. 2. “Which should you prefer for new code?

    Testing: Whether they know the industry already decided.

    Scoring

    Pass: Unchecked for almost everything. Checked exceptions do not compose across libraries, so callers either propagate everything or swallow it. Spring wraps SQLException in unchecked DataAccessException; Hibernate went unchecked in 3.0; C# and Kotlin have none.

    Fail: 'Checked is best practice' with no reasoning.

  3. 3. “What did Java 8 change about that argument?

    Testing: The structural, not aesthetic, reason.

    Scoring

    Pass: No standard functional interface declares throws, so a checked exception cannot escape a lambda. Every workaround converts it to unchecked at the boundary, so stream-friendly APIs must throw unchecked.

    Fail: Nothing / unaware of the lambda constraint.

  4. 4. “Beyond brevity, why use try-with-resources instead of finally?

    Testing: Suppressed exceptions — the real answer.

    Scoring

    Pass: In a hand-written finally, a close() that throws replaces the body's exception and destroys the real cause. try-with-resources keeps the body's exception primary and attaches the close failure via getSuppressed().

    Fail: 'It is shorter' or 'it closes automatically' and nothing more.

  5. 5. “Can a finally block swallow an exception?

    Testing: Control flow in finally.

    Scoring

    Pass: Yes — return, break or continue inside finally discards an in-flight exception, as does throwing from it. try { throw ... } finally { return 42; } returns 42.

    Fail: Says finally cannot affect the exception.

  6. 6. “int x = 1; try { return x; } finally { x = 2; } — what comes back?

    Testing: When the return value is evaluated.

    Scoring

    Pass: 1. The value is evaluated and copied before finally runs.

    Fail: 2.

  7. 7. “Should you ever catch Throwable?

    Testing: Error handling judgement.

    Scoring

    Pass: Almost never. It catches OutOfMemoryError and StackOverflowError plus every programming bug, turning crashes into silent corruption. Acceptable only in a top-level thread or request loop that logs and rethrows or exits.

    Fail: 'It is safer because it catches everything.'

  8. 8. “You catch InterruptedException and log it. What did you break?

    Testing: The most commonly mishandled exception in Java.

    Scoring

    Pass: Catching it clears the interrupt flag, so nothing upstream can tell the thread was asked to stop and pools stop shutting down cleanly. Either propagate it or call Thread.currentThread().interrupt() to restore the flag.

    Fail: Sees nothing wrong with logging and continuing.

Score yourself

8/8 — you can hold this at senior level 6-7 — solid; reread "Interviewer's Next Move" 4-5 — you know the definitions, not the consequences; redo the Challenge 0-3 — run the Production exercise, then reread "Understand It"

← Back to What is the difference between checked and unchecked exceptions?