本帖最后由 记得上线 于 2012-7-4 17:25 编辑
编写异常需要对电脑设置吗,我编译老报错。
class FuShuException extends Exception
{
}
class DDemo
{
int div(int a,int b)throws FuShuException//在功能上通过关键字声明了该功能有可
能会出现异常。
{
if(b<0)
throw new FuShuException("出现了除数是负数的情况------ / by
fushu",b);
return a/b;
}
}
class EExceptionDemo
{
public static void main(String[] args)
{
Demo d=new Demo();
try
{
int x=d.div(3,-1);
System.out.println(x);
}
catch(FuShuexception e)
{
System.out.println(e.toString());
System.out.println(除数为-1);
}
}
}
[img]file:///C:/Documents%20and%20Settings/Administrator/Application%20Data/Tencent/Users/619034576/QQ/WinTemp/RichOle/S8R8O5][7005WIX{ZE1E0[M.jpg[/img]
|
|