From the course: Complete Guide to Spring MVC

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Exceptions overview

Exceptions overview

- [Instructor] Exceptions overview. When looking at your controller and controller advice classes, these can have exception handler methods to handle exceptions from controller methods. What is an exception handler? The exception handler annotation allows you to define custom methods to handle exceptions thrown by your controller methods instead of letting exceptions propagate to the user. So you don't want to cause app crashes or expose stack traces Spring lets you gracefully intercept them and provide custom responses or actions. So let's jump into IntelliJ to see this at play. Again, we are in our greeting controller class and I've added in this snippet to save us a bit of time and I'll walk you through what we have here. Okay? All right, so we want to add an exception handler to our code to handle exceptions such as invalidate format errors from the example that we had before where we had a custom date format. All right? So what I've done here is I've added exception handler, and…

Contents