class Demo
{
int div(int a,int b)throws Exception
{
return a/b;
}
}
class ExceptionDemo
{
public static void main(String[] agrs)throws Exception
{
Demo d = new Demo();
int x = d.div(4,0);
System.out.println("x="+x);
System.out.println("over");
}
}
和
class Demo
{
int div(int a,int b)
{
return a/b;
}
}
class ExceptionDemo
{
public static void main(String[] agrs)
{
Demo d = new Demo();
int x = d.div(4,0);
System.out.println("x="+x);
System.out.println("over");
}
}
执行程序都一样的报错,报错内容都一样,要不要加上throws Exception? |