黑马程序员技术交流社区

标题: 看看这个自定义异常程序为什么编译失败 [打印本页]

作者: 胡威    时间: 2011-11-26 20:59
标题: 看看这个自定义异常程序为什么编译失败
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
问:出错在哪里啦

作者: 梁锡伟    时间: 2011-11-26 22:10
。。。。没错啊。。。你没有public修饰符不能运行?
作者: 颜小飞    时间: 2011-11-27 14:03
我没找到问题
作者: 侯伟浩    时间: 2011-11-27 14:07
至少有个public 的class啊




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