Quick revision
The short answer
Mostly yes, with one important exception. Checked exceptions make failure part of a method's signature, but in practice they produce catch-and-wrap boilerplate or swallowed exceptions, they do not compose with lambdas and streams, and Spring's translation into an unchecked, technology-neutral DataAccessException hierarchy lets callers catch only what they care about. Unchecked exceptions keep code clean and let handling happen at a boundary, but callers may not know what can fail, so a reasonable default is unchecked exceptions for infrastructure failures and explicit result types, or clearly documented exceptions, for expected business outcomes.
What to remember
In this answer, we argued both sides. Checked exceptions put failure into the signature and make changes visible, but in services they mostly produce catch-and-wrap boilerplate or swallowed failures, do not compose with lambdas and streams, and leak implementation details. Unchecked exceptions keep code clean and move handling to a boundary, at the cost of callers not knowing what can fail, and Spring's DataAccessException translation gives a consistent, technology-neutral hierarchy that callers catch selectively. The default we chose is unchecked exceptions for infrastructure failures and explicit result types or documented exceptions for expected business outcomes.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Mostly yes, with one important exception. Checked exceptions make failure part of a method's signature, but in practice they produce catch-and-wrap boilerplate or swallowed exceptions, they do not compose with lambdas and streams, and Spring's translation into an unchecked, technology-neutral DataAccessException hierarchy lets callers catch only what they care about. Unchecked exceptions keep code clean and let handling happen at a boundary, but callers may not know what can fail, so a reasonable default is unchecked exceptions for infrastructure failures and explicit result types, or clearly documented exceptions, for expected business outcomes.
Why this question is asked
Every service team eventually argues about exceptions. Some engineers want checked exceptions so the compiler forces handling; others point to Spring, Kotlin and most modern libraries, which use only unchecked ones. Interviewers ask this as a leadership question because the right answer is a reasoned default the team can follow, not a slogan. In this answer, we will recap what Spring does with SQLException, make the case for checked exceptions, make the case against them, look at what the unchecked approach costs, and then set a default for our services with an example of each kind of failure.
1What Spring Does With SQLException
JDBC reports every database problem as SQLException, a checked exception, with a vendor-specific error code and SQL state. Code written against plain JDBC must catch or declare it everywhere, and to tell a duplicate key from a lost connection, it must inspect codes that differ between PostgreSQL, MySQL and Oracle.
Spring's data access support catches SQLException at the edge, in JdbcTemplate or in repository proxies, and translates it into a subclass of DataAccessException, which is a RuntimeException. The subclasses describe what went wrong in technology-neutral terms: DuplicateKeyException, DataIntegrityViolationException, OptimisticLockingFailureException, and transient ones such as QueryTimeoutException under TransientDataAccessException. The same hierarchy is used for JPA and other stores.
- Controller advicemaps leftover exceptions to HTTP 500 or 503
- Servicecatches
DuplicateKeyExceptiononly, if it can act - Repository / JdbcTemplatetranslates SQLException to
DataAccessException - JDBC driverthrows SQLException with SQL state 23505
4 layers, from the top down. Step through them one at a time.
2The Case for Checked Exceptions
The strongest argument is that a checked exception makes failure visible in the signature. A reader of Account withdraw(long cents) throws InsufficientFundsException knows a normal outcome other than success exists, and the compiler will not let any caller forget it. When failures are part of the business, such as a payment declined or a booking unavailable, that is valuable: forgetting to handle them is a real bug, and the compiler catches it.
Checked exceptions also make changes visible. If a method starts throwing a new checked exception, every caller fails to compile until someone decides how to handle it, whereas a new unchecked exception would only appear in production.
3The Case Against Checked Exceptions
In practice, most checked exceptions in services are infrastructure failures that the immediate caller cannot do anything about. A repository method that throws SQLException forces its service, then its controller, to catch or declare it. What developers actually write is catch-and-wrap boilerplate, or worse, an empty catch block that swallows the failure.
The second example is the bigger problem today. The standard functional interfaces, Function, Supplier, Consumer, declare no checked exceptions, so a lambda that calls a method throwing SQLException does not compile. Teams end up writing wrapper utilities or unchecked rethrows, which removes the benefit the checked exception was supposed to provide. Checked exceptions also leak implementation details: a service interface that declares SQLException cannot later switch to a REST call without changing its signature. Spring's translation fixes all three problems for infrastructure failures.
4What Unchecked Exceptions Cost
Unchecked exceptions keep code clean and let handling happen once, at a boundary such as a @RestControllerAdvice, a message listener's error handler or a job wrapper. But nothing tells the caller what can fail. A service can throw DuplicateKeyException from a method whose signature looks infallible, and the first time a developer learns about it is a 500 error in production. Documentation with @throws helps, and tests help more, but the compiler no longer checks. So the honest summary is that unchecked exceptions are right where handling belongs at the boundary, and weaker where every caller must make a decision.
5A Default for Our Services
I would set this default. Infrastructure failures, databases, networks, serialization, configuration, are unchecked, using Spring's DataAccessException and similar hierarchies, and are handled at the boundary: logged, counted, retried where the failure is transient, and mapped to a 503 or 500. Expected business outcomes, which a caller must decide about, are modelled explicitly: either as a result type, such as a sealed interface with Success and Declined records, or as a documented unchecked exception from a small, named business hierarchy when that fits the framework better. We do not introduce new checked exceptions in internal APIs, but we do not fight libraries that use them either; we translate them at the edge.
| Kind of failure | How we model it | Where it is handled |
|---|---|---|
| Database, network, timeouts | unchecked, DataAccessException etc. | boundary: retry, log, 503 or 500 |
| Programming errors | IllegalArgument, IllegalState | fixed in code, 500 at boundary |
| Expected business outcomes | sealed result type | the immediate caller, checked by switch |
| Business rule violation, rare | documented unchecked exception | advice maps it to 409 or 422 |
| Library checked exceptions | translated at the edge | never leak past the adapter |
Notice that the sealed result type gives back the benefit checked exceptions promised, the compiler checks that every outcome is handled, but it composes with streams and lambdas and does not leak infrastructure. It is the best of both sides for expected outcomes.
6Follow-up questions
Doesn't the sealed result type just reinvent checked exceptions?
Partly, and that is intended: it keeps the compile-time check for outcomes that callers must handle. The differences are that it is a value, so it works in streams and lambdas, that it cannot propagate silently up the stack, and that it is only used where the caller really has a decision to make.
How do you make unchecked exceptions discoverable?
Document them with @throws on public methods, keep a small, named business exception hierarchy instead of throwing RuntimeException, test the error paths, and map each exception to an explicit HTTP status in one advice class, which then also serves as a list of what the service can fail with.
When would you still use a checked exception?
In a library whose callers genuinely must handle a recoverable condition and where lambdas are not the main usage, or when extending a framework that requires one, such as implementing a JDK interface that declares IOException.
7Conclusion
In this answer, we argued both sides. Checked exceptions put failure into the signature and make changes visible, but in services they mostly produce catch-and-wrap boilerplate or swallowed failures, do not compose with lambdas and streams, and leak implementation details. Unchecked exceptions keep code clean and move handling to a boundary, at the cost of callers not knowing what can fail, and Spring's DataAccessException translation gives a consistent, technology-neutral hierarchy that callers catch selectively. The default we chose is unchecked exceptions for infrastructure failures and explicit result types or documented exceptions for expected business outcomes.
Open with
I think unchecked is the right default for infrastructure failures, but not for everything. The argument for checked exceptions is real: the failure is in the signature and the compiler makes every caller handle it, and adding one breaks callers' builds, which is a feature when the failure matters.
Then, if they want more
The problem is what happens in practice in services. Most checked exceptions are infrastructure failures like SQLException that the immediate caller cannot handle, so people wrap them or, worse, swallow them and return null.
They also do not work with lambdas and streams, because Function and Supplier cannot throw checked exceptions, and they leak implementation: a service declaring SQLException cannot switch storage without changing its API.
Spring's translation solves that well: SQLException becomes an unchecked DataAccessException subtype like DuplicateKeyException, technology-neutral, and I catch only the ones I can act on; everything else goes to a boundary handler that logs, retries if transient, and returns a 503 or 500.
The cost of unchecked is that callers do not know what can fail, so for expected business outcomes, like a declined payment, I model them explicitly, for example a sealed result type the caller has to switch over, or at least a documented business exception.
So: unchecked for infrastructure, explicit results for business outcomes, no new checked exceptions in internal APIs.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Spring translates checked SQLExceptions into an unchecked DataAccessException hierarchy...": https://scrivio-interview-library.netlify.app/java/exceptions/dd8fba57d7/