Application exception hierarchy
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
design a small set of exceptions.
Planned topics
- Define a base
ShopException(unchecked) and a few subclasses:NotFoundException,ConflictException,BusinessRuleException. - Services throw them; they say what happened, not which HTTP status.
- Carry useful data: the entity name and id.
- Keep the tree small; do not create one class per message.
Draft outline details
Demonstration
public class NotFoundException extends ShopException {
public NotFoundException(String entity, Object id) { super(entity + " " + id + " not found"); }
}Check your understanding
Does the service choose the HTTP status?
Show answer
No; the advice maps the exception to a status.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.