@ExceptionHandler doesn't handle the thrown exceptions

Posted by Javi on Stack Overflow See other posts from Stack Overflow or by Javi
Published on 2010-05-20T08:32:58Z Indexed on 2010/05/20 9:50 UTC
Read the original article Hit count: 148

Hello,

I have a method in my controller which will handle the exceptions thrown by the application. So I have a method like this one.

@Controller
public class ExceptionController {

    @RequestMapping(value="/error")
    @ExceptionHandler(value={Exception.class, NullPointerException.class})
    public String showError(Exception e, Model model){
        return "tiles:error";
    }
}

And to try I if it works I throw a NullPointerException in another method in other method controller:

boolean a = true;
if(a){ 
    throw new NullPointerException();
}

After the exception is thrown it is printed in the JSP, but it doesn't go throw my showError() method (I've set a breakpoint there and it never enters). showError() method will catch the exception and will show different error pages depending on the exception type (though now it always shows the same error page). If I go to the url /error it shows the error page so the showError() method is OK.

I'm using Spring 3.

What can be the problem?

Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about spring