class FuShuException extends Exception
{
private int value;
FuShuException(String msg,int value)
{
super(msg);
this.value=value;
}
public int getValue()
{
return value;
}
}
class Demo
{
public int div(int x,int y)throws FuShuException
{
if(y<0)
throw new FuShuException("除数是负数后面",y);
return x/y;
}
}
class ExceptionDemo3
{
public static void main(String[] args)
{
Demo d=new Demo();
try
{
int x=d.div(5,-3);
System.out.println("x="+x);
}
catch (FuShuException e)
{
System.out.println(e.toString());
System.out.println("该负数是"+e.getValue());
}
System.out.println("over");
}
}
编译出错:16行 public int div(int x,int y)throws FuShuException 不兼容的类型
需要:Throwable
找到:FuShuException
问:出错在哪里啦
|
|