0

I want to handle custom errors like 401, 403, 500 etc in Spring 3.2 application using Filters . I do not want to use the web.xml approach of defining the error pages.

I tried to follow the solution listed at How to handle exceptions thrown while rendering a view in Spring MVC?

But ErrorHandler.handle does not really exist.

How can I use filters to catch all the errors and redirect to different views ?

Community
  • 1
  • 1
Novice User
  • 3,552
  • 6
  • 31
  • 56

1 Answers1

1

A good way to handle exceptions in Spring Controllers is using the @ExceptionHanldler @ControllerAdvice annotations. Here is the relevant part of the documentation and here is a tutorial on their usage.

geoand
  • 60,071
  • 24
  • 172
  • 190
  • I did it ... Its apt for most of my needs too ..but i want it to not work for one Exception class ... how can I exclude that exception class from @ExceptionHandler(Exception.class) annotation – Novice User Apr 08 '14 at 06:33
  • 1
    You can add a second @ExceptionHandler(MyOTherException.class) which will handle only that case. The handler that you have already added will take care of all the other exceptions. – geoand Apr 08 '14 at 06:35