标题:异常处理
取消只看楼主
yu1543054075
Rank: 1
等 级:新手上路
帖 子:102
专家分:8
注 册:2015-4-30
结帖率:90.24%
已结贴  问题点数:5 回复次数:1 
异常处理
public class CatchWho2 {
    public static void main(String[] args) {
        try{
            try {
                throw new ArrayIndexOutOfBoundsException();
            }
            catch(ArithmeticException e) {
                System.out.println(
                  "ArrayIndexOutOfBoundsException" +
                  "/内层 try...catch");
                }
                throw new ArithmeticException();
            }
            catch(ArithmeticException e) {
                System.out.println("发生ArithmeticException");
            }
            catch(ArrayIndexOutOfBoundsException e) {
                System.out.println(
                   "ArrayIndexOutOfBoundsException" +
                   "/外层 try...catch");
                 }
                }
            }
结果显示为:
ArrayIndexOutOfBoundsException/外层 try...catch
为什么没有显示“发生ArithmeticException”
搜索更多相关主题的帖子: public 
2015-06-03 20:37
yu1543054075
Rank: 1
等 级:新手上路
帖 子:102
专家分:8
注 册:2015-4-30
得分:0 
版主能够给我讲解一下吗?我的程序为什么没有显示“发生ArithmeticException”, throw new ArithmeticException();这里扔出的异常不是应该被下面的 catch(ArithmeticException e)所捕捉么?
还有为什么你添加了一个 System.out.println(1/0);就行了呢
2015-06-04 14:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-446154-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015393 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved