Package com.example.springrest.exceptions
package com.example.springrest.exceptions
This package defines custom exceptions for the application.
Exceptions in this package extend standard Java or Spring exceptions to represent domain-specific error conditions. They improve readability and allow centralized error handling.
Responsibilities
- Provide meaningful exception types (e.g.
ProductNotFoundException
). - Support fine-grained error handling and more descriptive API responses.
- Work in tandem with
@ControllerAdvice
and Spring's exception handling mechanisms to translate exceptions into HTTP responses.
Design Notes
- Prefer runtime exceptions for domain errors to reduce boilerplate.
- Group related exceptions into this package for maintainability.
- Document exception behavior in service and controller methods.
- See Also:
-
ClassDescriptionGlobal exception handler for REST controllers.Exception thrown when a requested resource cannot be found.