zoukankan      html  css  js  c++  java
  • 多层的异常捕获

    CatchWho.Java

    源代码:

    public class CatchWho { 

        public static void main(String[] args) { 

            try { 

                try { 

                    throw new ArrayIndexOutOfBoundsException(); //要处理的问题

                 } 

                catch(ArrayIndexOutOfBoundsException 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

                         ArrayIndexOutOfBoundsException/外层try-catch

    实际运行结果截图:

    源代码:

    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

                      ArrayIndexOutOfBoundsException/外层try-catch

    实际运行结果截图:

  • 相关阅读:
    实验 MPLS LDP配置
    IEEP-OSPF域内路由故障-现象与排障思路
    IEEP部署企业级网络工程-OSPF邻居关系故障排除
    IEEP部署企业级网络工程-网络故障-环路故障
    IEEP-网络实施-项目交付流程
    Python正则表达式
    如何解决TortoiseSVN不显示状态小图标问题
    如何在win下一键升级 python 所有包
    vmware workstation 与 device/credential guard 不兼容
    windows系统中在jupyter安装虚拟环境内核
  • 原文地址:https://www.cnblogs.com/1995-qxl/p/4964266.html
Copyright © 2011-2022 走看看