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 com.neeti.neg.controller; /** * * @author manishas */ import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.servlet.ModelAndView; import com.neeti.neg.exception.NEGRuntimeException; @ControllerAdvice public class GlobalExceptionController { @ExceptionHandler(NEGRuntimeException.class) public ModelAndView handleCustomException(NEGRuntimeException ex) { ModelAndView model = new ModelAndView("errorpage"); model.addObject("errMsg", ex.getMessage()); return model; } @ExceptionHandler(Exception.class) public ModelAndView handleAllException(Exception ex) { ModelAndView model = new ModelAndView("errorpage"); model.addObject("errMsg", ex.getMessage()); ex.printStackTrace(); return model; } }