Friday, January 4, 2013

[Android] e.printStackTrace() ; 是什麼意思?

try{ 
BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); 
String inputLine=input.readline(); 
int i=Integer.parseInt(inputLine).intValue(); 
} 
catch(Exception e){ 
e.printStackTrace() ; 
}

在后面加e.printStackTrace() ;是为什么?

catch(Exception e){
e.printStackTrace() ;
} 
当try语句中出现异常是时,会执行catch中的语句,java运行时系统会自动将catch括号中的Exception e 初始化,也就是实例化Exception类型的对象。e是此对象引用名称。然后e(引用)会自动调用Exception类中指定的方法,也就出现了e.printStackTrace() ;。
printStackTrace()方法的意思是:在命令行打印异常信息在程序中出错的位置及原因。(这是白话解释,比较容易理解)

No comments:

Post a Comment