当前位置: 技术问答>java相关
问一个简单的Exception问题
来源: 互联网 发布时间:2015-10-30
本文导语: catch(Exception expe) { System.out.println("PlanList.Add 异常"+expe.getMessage()); expe.printStackTrace(); //这句做什么用? throw new EAPException(expe.getMessage()); ...
catch(Exception expe)
{
System.out.println("PlanList.Add 异常"+expe.getMessage());
expe.printStackTrace(); //这句做什么用?
throw new EAPException(expe.getMessage());
//这句做什么用?为什么要throw new EAPException?
}
{
System.out.println("PlanList.Add 异常"+expe.getMessage());
expe.printStackTrace(); //这句做什么用?
throw new EAPException(expe.getMessage());
//这句做什么用?为什么要throw new EAPException?
}
|
catch(Exception expe)
{
System.out.println("PlanList.Add 异常"+expe.getMessage());
expe.printStackTrace(); //会在控制台上线是错误的信息。
throw new EAPException(expe.getMessage());
//这句做什么用?为什么要throw new EAPException?
作用是抛出一个自定义的异常。这样,你就可以在调用这个方法的时候,用你自己的异常处理系统来相应一些常见的异常。
}
public void printStackTrace()
Prints this Throwable and its backtrace to the standard error stream. This method prints a stack trace for this Throwable object on the error output stream that is the value of the field System.err. The first line of output contains the result of the toString() method for this object. Remaining lines represent data previously recorded by the method fillInStackTrace(). The format of this information depends on the implementation, but the following example may be regarded as typical:
{
System.out.println("PlanList.Add 异常"+expe.getMessage());
expe.printStackTrace(); //会在控制台上线是错误的信息。
throw new EAPException(expe.getMessage());
//这句做什么用?为什么要throw new EAPException?
作用是抛出一个自定义的异常。这样,你就可以在调用这个方法的时候,用你自己的异常处理系统来相应一些常见的异常。
}
public void printStackTrace()
Prints this Throwable and its backtrace to the standard error stream. This method prints a stack trace for this Throwable object on the error output stream that is the value of the field System.err. The first line of output contains the result of the toString() method for this object. Remaining lines represent data previously recorded by the method fillInStackTrace(). The format of this information depends on the implementation, but the following example may be regarded as typical: