0

I am working on a spring project which has several classes. Now the code in that project is not up to the standard because of which there are no try catch blocks defined in any of the classes. I have the following mapping in my web.xml

<error-page>
    <exception-code>404</exception-type>
    <location>/error.do</location>
</error-page>

the /error.do is mapped to a controller from where its forward to a generic error view . Now ,will it be possible to get the stacktrace of my exception. My only requirement is to get the exception details in that error handler like -- where exception originated like class name, method name and exception message which i felt will be available in stack trace. Any idea how to proceed with this problem statement?

3
  • The above defines an error page for "404 not found" errors. 404 happens when a request for an unknow resource is received. Not when an exception is thrown from a Spring controller.
    – JB Nizet
    Mar 15, 2013 at 11:46
  • but even when there are generic exception when i m not catching, it goes to this controller. this is not handling just 404 errors. Mar 15, 2013 at 12:20

1 Answer 1

0

Yes you can do it Spring provides @ExceptionHandler annotation.So in your controller write one method as :

@ExceptionHandler(YourException.class)
public ModelAndView handleYourException(YourException ex, HttpServletRequest request) {
    mav = new ModelAndView();
    mav.addObject("exception", exception);
    mav.setViewName("YourException Page");
    return mav;
}

Hope you got my point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.