2 treagzhao treagzhao 于 2013.07.23 16:31 提问

SSH框架的UndeclaredThrowableException问题

我正在学习SSH框架,用到了struts的异常捕获机制。我自定义了一个异常类型,在异常处理类里面通过判断是否是这个类的实例来进行不同的处理。可是我能接受到的异常,全部是UndeclaredThrowableException,这个何解?一下是抛出事件的类:

`public class LoginInterceptor implements MethodBeforeAdvice {
public void before(Method method, Object[] args, Object instance)
        throws Exception {
    ActionMapping mapping = (ActionMapping) args[0];
    ActionForm form = (ActionForm) args[1];

    HttpServletRequest request = (HttpServletRequest) args[2];
    HttpServletResponse response = (HttpServletResponse) args[3];

    boolean needsCheck = true;
    if (needsCheck && PersonUtil.getPersonInfo(request, response) == null) {    
        throw new TempException("您还没有登录");
    }
}

}`

一下是处理异常的类

public class ForumExceptionHandler extends ExceptionHandler {

@Override
public ActionForward execute(Exception ex, ExceptionConfig ae,
        ActionMapping mapping, ActionForm formInstance,
        HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    System.out.println((ex.getClass()) + " aaaaaaa");
    System.out.println((ae) + " aaaaaaa");
    request.setAttribute("exception", ex);

    if (ex instanceof AccountException) {
        return new ActionForward("login", "/index.jsp", false);
    }
    return new ActionForward("exception", "/pages/exception.jsp", false);
}

}
一下是配置文件:

    <global-exceptions>
    <exception key="login" type="com.forum.exception.TempException"
        handler="com.forum.exception.ForumExceptionHandler">
    </exception>
    <exception key="login" type="javax.security.auth.login.AccountException"
        handler="com.forum.exception.ForumExceptionHandler">
    </exception>
    <exception key="login" type="java.lang.Exception"
        handler="com.forum.exception.ForumExceptionHandler">
    </exception>
</global-exceptions>
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!