日期:2014-05-20  浏览次数:20712 次

关于try catch问题
public   class   ReadLine
{
public   static   void   main(String   []   args)
{
byte   buf[]=new   byte[1024];
String   strInfo=null;
int   pos=0;
int   ch=0;
System.out.println( "please   enter   info,   input   bye   for   exit: ");
while(true)
{
try
{                        
ch=System.in.read();
}
catch(Exception   e)
{
System.out.println(e.getMessage());
}
switch(ch)
{
case   '\r ':
break;
case   '\n ':
strInfo=   new   String(buf,0,pos);
if(strInfo   ==   "bye ")
return   ;
else
System.out.println(strInfo);
pos=0;
break;
default:
buf[pos++]=(byte)ch;
}
}
}
}
在这个程序中
catch(Exception   e)
{
    System.out.println(e.getMessage());
}
e.getMessage()这个到底是什么意识阿   应该怎么理解阿?



------解决方案--------------------
一个exception的getmessage方法将会返回这个e的整个异常链中第一个message不为null的message:-)
message什么意思想想也知道了啊。
------解决方案--------------------
e.getMessage()就是java封装好的异常信息,这就是你调试程序出错的依据啊