黑马程序员技术交流社区

标题: 问个关于Exception的问题 [打印本页]

作者: wangenbin    时间: 2016-1-13 22:07
标题: 问个关于Exception的问题
No exception of type Exception can be thrown; an exception type
must be a subclass of Throwable
这句话是什么意思啊
还有下面一段代码,为什么没办法抛异常
class Demo
{
        int div(int a,int b) throws Exception
        {
                return a/b;
       
        }
}
class Exception
{
        public static void main(String[] args) throws Exception
        {
                Demo d=new Demo();
               
                        int x=d.div(4,1);
                        System.out.println("x="+x);
                        System.out.println("over");
               
               
               
        }
}
求助
作者: wangenbin    时间: 2016-1-13 22:46
抛RuntimeException就可以了,是抛大了吗?
作者: rushing    时间: 2016-1-13 22:50
看看学习一下




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