class FuShuException extends Exception{
private int val;
FuShuException(String mess,int val){
super(mess);
this.val = val;
}
public int getVal(){
return val;
}
}
class Demo{//Demo这显示错误
int div(int a ,int b)throws FuShuException{
if(b<0)
throw new FuShuException("出现负数",b);
return a/b;
}
}
public class ExceptionDemo2{
public static void main(String args []){
Demo d = new Demo();
try{
int x = d.div(4,-1);//传入数字测试
System.out.println("x = "+x);
} catch(FuShuException e){
System.out.println("程序出现异常");
System.out.println(e.toString());
System.out.println("错误数字:"+ e.getVal());
}
System.out.println("OVER");
}
}
看毕老师视频,写的这个代码,怎么上边Demo类这出现错误。。。求解释。。。
|