class ZiYiException extends Exception
{
private String name;
public String getMessage(String name)
{
this.name=name;
return name;
}
}
class QiuHe
{
int sum(int x,int y,int z)throws ZiYiException
{
if(x<0)throw new ZiYiException().getMessage("wrong");
return x+y+z;
}
}
class ExceptionDemo
{
public static void main(String[] args)
{
int sum;
try
{
sum=new QiuHe().sum(-1,5,6);
System.out.println(sum);
}
catch (Exception e)
{
System.out.println(e.toString());
}
System.out.println("over");
}
}
程序中我自定义了一个异常,里面同过getMessage的方法实现对name赋值,实现对出现异常的详细描述,但就是不能编译,我怎么检查就是查不出来,这到底是那儿出现了问题啊
|