Use a checked exception only when the caller can realistically recover and you want the compiler to force a decision; use unchecked for programming errors and for failures nobody up the stack can fix. In practice most modern Java code leans unchecked, wrapping low level failures in a domain exception that carries context, handled once at a boundary such as an exception handler that maps it to a response.
Why interviewers ask this
The interviewer is probing for judgment and for habits that ruin codebases: catching Exception and logging it, swallowing an exception into an empty block, or wrapping everything in RuntimeException with no context. They also want to hear about a single translation layer, because scattering try catch through business logic is what makes failures untraceable. Lambdas and streams make checked exceptions genuinely awkward, which is worth naming.
How to structure your answer
- Give the recoverability test for choosing between the two.
- Explain wrapping with context rather than rethrowing raw causes.
- Describe handling in one boundary layer, not everywhere.
- List the antipatterns you refuse to accept in review.
Example answer
My test is whether a caller can do something useful about it. A payment declined by the provider is a legitimate business outcome, so that is either a checked exception or, more often, a result type. A null argument or a failed database connection is not something the calling code can fix, so it is unchecked. In services I mostly use unchecked domain exceptions, wrapping the underlying cause so the stack trace survives and adding the identifiers I will want in the log, like the order id, since a bare SQL exception three layers down tells me nothing. Handling happens once, at a boundary: in Spring that is an exception handler that maps each domain exception to a status code and a response body, so controllers stay clean. What I push back on in review is catching Exception broadly, catching and logging then continuing as if nothing happened, and empty catch blocks. I also use try with resources everywhere rather than finally blocks, because suppressed exceptions and close failures are handled correctly for free.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How do you deal with a checked exception inside a stream lambda?
- When would you return a result type instead of throwing?
- What context do you attach to an exception so it is useful in a log?
Related java developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions