class Demo
{
int div(int x,int y)throws Exception
{
return x/y;
}
}
class ExceptionDemo1
{
public static void main(String[] args)
{
Demo d=new Demo();
int x=d.div(4,1);
System.out.println("x="+x);
System.out.println("over");
}
}
编译时说需要对抛出的Exception捕获或抛出,如果会那为什么下面这个却Catch不到异常啊
class Demo
{
int div(int x,int y)throws Exception
{
return x/y;
}
}
class ExceptionDemo1
{
public static void main(String[] args)
{ Demo d=new Demo();
try
{
int x=d.div(4,1);
System.out.println("x="+x);
}
catch (Exception e)
{
System.out.println(e.toString());
}
System.out.println("over");
}
}
|