源代码如下:
public class MainClass {
public static void main(String[] args) {
A p1=new A();
try
{
System.out.println(p1.devide(1,-1));
}
catch(DevideByMinusException e2)
{
e2.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception!");
}
finally
{
System.out.println("finally!");
}
}
}class DevideByMinusException extends Exception
{
public DevideByMinusException(String s)
{
super(s);
}
}
class A
{
int[] aa=new int[10];
public float devide(int x,int y) //throws ArithmeticException
{
if(y<0)
throw new DevideByMinusException("less than 0!");
return (float)(x*1.0/y);
}
}
怎么这段代码不能完成编译啊??
错误提示是:
unreported exception DevideByMinusException:must be caught or declared to be thrown拜托各位了,我想了好久,但没找到原因,唉,郁闷死了哦~~~