代码如下
int columnPerPage = 20;
try{
columnPerPage = ((Integer)request.getSession().getAttribute("columnPerPage")).intValue();
}catch(Exception ex){
columnPerPage = 20;
//System.out.println(ex);
}心想:如果request.getSession().getAttribute("columnPerPage")为空那么就要抛出异常,通过catch语句块捕捉异常,给columnPerPage 初值20,那么程序可以继续运行而不退出事实是,调试发现,当程序运行完columnPerPage = 20;一句后就直接退出了并在控制台打印一大堆异常:
(主要异常信息:)
16:03:05,484 WARN  [RequestProcessor] Unhandled Exception thrown: class java.lang.NullPointerException
16:03:05,500 ERROR [Engine] StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
java.lang.NullPointerException