Posted by admin July 17th 2018 at 11:07

1. own exception class (using RuntimeException)

public class OwnException extends RuntimeException {

	private static final long serialVersionUID = 1L;
	private String resultCode = "0000";

	public OwnException(){
super(); } public OwnException(String message, String resultCode){
super(message); this.resultCode = resultCode; } public String getResultCode() { return resultCode; } public void setResultCode(String resultCode) { this.resultCode = resultCode; } }


2. add bean

<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
	<property name="exceptionMappings">
	    <props>
                ...
                <prop key="yourpackage.OwnException">view</prop>	
                ...
            </props>
        </property>
</bean>


3. handling exception in aop

@Before("execution(public * yourpackage.OtherController.*(..))")
    public void before(JoinPoint joinPoint) throws Exception{
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
		try{
			....
			....
			
		}catch(Exception e){
			throw new OwnException(e.getMessage(), "9999");
		}
    }