Java捕获被忽略

Java捕获被忽略,java,exception,try-catch,Java,Exception,Try Catch,我的头都快碎了: protected void setParameters(HttpServletRequest request) { try { page = Integer.parseInt(request.getParameter("p")); } catch (NumberFormatException | NullPointerException e) { messages.add("Invalid page."); }

我的头都快碎了:

protected void setParameters(HttpServletRequest request) {

    try {
        page = Integer.parseInt(request.getParameter("p"));
    }
    catch (NumberFormatException | NullPointerException e) {
        messages.add("Invalid page.");
    }

    try {
        status = Integer.parseInt(request.getParameter("s"));
    }
    catch (NumberFormatException | NullPointerException e) {
        messages.add("Invalid status.");
    }

}
在我将这个方法放入一个超类之前,它是按预期工作的;但是现在,当我有一个没有p参数的查询字符串时(例如),异常(NumberFormatException)被抛出(如预期的),然后被第一个捕获(如预期的)捕获,然后被调用函数重新捕获(这不是预期的)。因为这里已经捕获到异常,所以应该继续执行

我附上一个屏幕截图,您可以看到:

  • 粉红色:我的断点
  • 绿色:我当前的执行行
  • 作为气球:当前类型的异常,明确表示它是NumberFormatException

任何想法都非常感谢

更新:

谢谢,这是我的调用堆栈:Servlet>UserListHandler>setParameters

UserListHandler()是一个构造函数,如下所示:

Mar 31, 2014 5:13:06 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [UserListServlet] in context with path [/App.Web] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException

Servlet如下所示:

Mar 31, 2014 5:13:06 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [UserListServlet] in context with path [/App.Web] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException

我发现servlet捕获的异常是NullPointerException,这很有趣

堆栈跟踪的顶部如下所示:

Mar 31, 2014 5:13:06 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [UserListServlet] in context with path [/App.Web] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException

显然还有另一个例外


可能catch中的“messages”为null,并且它正在抛出一个新的NullPointerException?

能否显示调用代码以及它是否也捕获了已处理的异常的任何证据?堆栈跟踪在哪里表明引发了异常?显然,其他地方也在抛出异常。第一个例外,屏幕截图中的一个,它无法逃脱catch块。如果另一个在某处被抓到,这意味着有两个例外。可能重复的非常感谢大家。。。是的,有一个空指针异常,因为有一个从未初始化过的变量。我觉得太愚蠢了!,非常感谢@Alfcope,消息从未实例化过。也要感谢所有其他人!事情发生了。我认为每个人都至少犯过一次同样的错误。