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

try catch语句
class Test
{

int devide(int x,int y)
{
int reslut=0;
reslut=x/y;
return x/y;
}
}
class TestException
{
public static void main(String [] args)
{
try
{
int reslut=new Test().devide(3,1);
System.out.println(reslut);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("programe is running here,that is nomare");

}
}

--------------------配置: <默认>--------------------
F:\4\TestException.java:20: incompatible types
found : Exception
required: java.lang.Throwable
  catch(Exception e)
  ^
F:\4\TestException.java:22: cannot resolve symbol
symbol : method getMessage ()
location: class Exception
  System.out.println(e.getMessage());
  ^
2 errors

处理已完成。



------解决方案--------------------
你的Exception有问题
重装下JDK看看
------解决方案--------------------
估计是你在这个目录下(或者说当前包下)自己写了个名叫Exception的类。
自己写的类,名字最好不要个java.lang包底下的类重名,否则出了错,你都不好查。除非你确实知道自己在做什么。
------解决方案--------------------
我测了下,你的程序没有问题,
还是重新安装jdk吧,省事方便