Skip to content
Ameen Abozaid
Planned lessonJNR-015-L02

Application exception hierarchy

  • Lesson 2 of 6
  • Junior
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

java
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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.