• 多层的异常捕获


    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

    实际运行结果截图:

  • 相关阅读:
    Android模拟器中访问局域网地址
    wifidirect
    asp.net上传图片自动生成缩略图功能代码
    Asp.Net二级域名共享Forms身份验证、下载站/图片站的授权访问控制
    最简单的三层实例【插入据
    使用RGBa和Filter实现不影响子元素的CSS透明背景
    Jquery ui widget开发
    SQL优化
    SQL SERVER 数据类型
    SQL Server数据库查询速度慢的原因
  • 原文地址:https://www.cnblogs.com/1995-qxl/p/4964266.html
Copyright © 2020-2023  润新知