Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package rashjz.info.com.az.config; import javax.servlet.http.HttpServletRequest; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.servlet.ModelAndView; /** * * @author Mobby */ @ControllerAdvice class AdviceController { public static final String DEFAULT_ERROR_VIEW = "error"; @ExceptionHandler(value = Exception.class) public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception { // If the exception is annotated with @ResponseStatus rethrow it and let // the framework handle it - like the OrderNotFoundException example // at the start of this post. // AnnotationUtils is a Spring Framework utility class. if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e; } // Otherwise setup and send the user to a default error-view. ModelAndView mav = new ModelAndView(); mav.addObject("exception", e); mav.addObject("url", req.getRequestURL()); mav.setViewName(DEFAULT_ERROR_VIEW); return mav; } // // @ExceptionHandler // @ResponseStatus(HttpStatus.NOT_FOUND) // public ModelAndView handleException(NoSuchRequestHandlingMethodException ex) { // ModelAndView mav = new ModelAndView(); // return mav; // } // // @ExceptionHandler // @ResponseStatus(HttpStatus.NOT_FOUND) // public ModelAndView handleExceptiond(NoHandlerFoundException ex) { // ModelAndView mav = new ModelAndView(); // return mav; // } // // @ResponseStatus(HttpStatus.NOT_FOUND) // @ExceptionHandler(NoHandlerFoundException.class) // public void handleConflict() { // // } // // @ResponseStatus(HttpStatus.NOT_FOUND) // @ExceptionHandler(NoSuchRequestHandlingMethodException.class) // public void handlesdConflict() { // } }