黑马程序员技术交流社区

标题: 为什么有这样的错? [打印本页]

作者: lizequn007wo    时间: 2015-7-27 22:02
标题: 为什么有这样的错?
class FuShuException extends Exception{
private String msq;
FuShuException(String msq){
this.msq=msq;
}
public String getMessage(){
return msq;
}
}
class Demo{
int div(int a,int b)throws FuShuException
{
if(b<0)
throw new FuShuException();
return a/b;
}
}
class Exceptiondemo11{
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(e.toString());

}}}

6001aec27d1ed21b333bbbe4ab6eddc450da3f52.jpg (34.68 KB, 下载次数: 13)

异常

异常

作者: maizi1912    时间: 2015-7-27 22:07
throw的时候 你的自定义异常构造函数  是有参数的  要传递一个参数
作者: Wqi    时间: 2015-7-27 22:38
FuShuException(String msq){
this.msq=msq;
}你的自定义构造函数有参数。所以新建对象要传参数。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2