At present I am able to handle excetions at controller level.. I have added this method in all controller classes to handle the exceptions... It is working fine...
@ExceptionHandler(Exception.class)
public ModelAndView handleException(Exception e, HttpServletRequest r) {
String message = e.getMessage();
ModelAndView mv=new ModelAndView("exceptionPage", "message", message);
return mv;
}
But my question here is can we write a common controller which will handle all the exceptions?, So that I can avoid duplication of exception handling code... I tried this code but seems to be DispatcherServlet is looking the @ExceptionHandler(Throwable.class) annotation with in same controller class..
@Controller
public class ExceptionController {
@ExceptionHandler(Throwable.class)
public ModelAndView handleException(Throwable e, HttpServletRequest r) {
String message = e.getMessage();
ModelAndView mv=new ModelAndView("exceptionPage", "message", message);
return mv;
}
}
Thanks in advance..


Reply With Quote