Sobes.tech
Senior

Are checked exceptions present in Spring?

sobes.tech AI

Answer from AI

Spring Framework itself does not introduce new types of exceptions but uses standard Java exceptions. In Java, there are checked exceptions and unchecked exceptions.

However, in Spring, it is common to use unchecked exceptions (RuntimeException and its subclasses) for most cases, especially in DAO and service layers. This is because checked exceptions complicate code and handling, and Spring provides transaction and error handling mechanisms that work better with unchecked exceptions.

For example, in Spring Data JDBC or JPA, exceptions are wrapped in DataAccessException — an unchecked exception.

Therefore, Spring itself does not have its own checked exceptions, and the recommended practice is to use unchecked exceptions to simplify error handling.

Are checked exceptions present in Spring? — Java - sobes.tech