Concept
A @RestControllerAdvice turns exceptions into consistent HTTP responses in one place: the status, a stable error code and a message. Controllers then do not need try and catch at all.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Error handling with advice doing its job.
@RestControllerAdvice
class ApiErrors {
@ExceptionHandler(NotFoundException.class)
ProblemDetail notFound(NotFoundException e) {
var problem = ProblemDetail.forStatus(HttpStatus.NOT_FOUND);
problem.setDetail(e.getMessage());
return problem;
}
@ExceptionHandler(MethodArgumentNotValidException.class)
ProblemDetail invalid(MethodArgumentNotValidException e) { /* field errors */ }
}A catch-all handler that returns the exception message for every Throwable. Internal details and stack traces end up in client responses; map known exceptions and return a generic 500 for the rest.
Your roadmap puts these before Error handling with advice, unless you already know them.
Once a session shows you understand Error handling with advice, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.