异常
异常有两种处理办法——Ⅰ,捕获:try—catch块处理 Ⅱ,传递:方法throws 异常,这样该方法抛出的异常会被传递给调用者,调用者要么处理,要么继续传递
异常的继承结构图
Error,RuntimeException是非受查异常,IOException是受查异常
如果出现了RuntimeException那么一定是你的问题
原来代码:
try{........
}catch(SQLException e)
{ throw new ServletException("datebase error:"+e.getMessage( ) );
以下会更好——把原始异常设为新异常的“原因”
try{.....}
catch(SQLException e){
Throwable se=new ServletException("datebase error");
se.initCause(e);
throw se;
当捕获异常时,可以用Throwable e=se.getCause( );重新得到原始异常
堆栈轨迹跟踪
Throwable t=new Throwable( );
StackTraceElement[ ] frames=t.getStackTrace( );
for(StackTraceElement frame:frames).......