A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© kenhe 中级黑马   /  2014-12-10 20:12  /  1314 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

//异常处理方式 要么try 要么抛。
//但是下面我的程序抛出了一个ArithmeticException,主函数调用 既没有try 也没有抛
//也能正常运行 是怎回事?
class Demo
{
        int div(int a,int b) throws ArithmeticException
        {
                return a/b;
        }
}
class ExceptionTest
{
        public static void main(String[] args)
        {
                Demo d=new Demo();
                int x=d.div(3,1);
                System.out.println("x="+x);               
                System.out.println("over");
        }
}

3 个回复

倒序浏览
但是抛出的如果是Exception的话,如果不处理的话 就会报错了
回复 使用道具 举报
ArithmeticException    这个异常是RuntimeException的子类,编译时不会报错吧····
回复 使用道具 举报
不好意思 之前没看到那章节去 现在知道了 献丑了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马