/*
class FuShuException extends Exception
{
FuShuException(String msg)
{
super(msg);
}
}
*/
class Demo
{
int div(int a,int b)throws FuShuException
{
if(b<0)
throw new FuShuException("出现了负数");
return a/b;
}
}
class ExceptionDemo1
{
public static void main(String[] args)//throws Exception
{
Demo d=new Demo();
try
{
int x=d.div(4,-1);
System.out.println("x="+x);
}
catch (FuShuException e)
{
System.out.println("除数出现负数了");
}
}
}
这个程序把上面的FuShuException类去掉为什么编译和运行都正常?
|
|