zoukankan      html  css  js  c++  java
  • 嵌套的Try-Catch块--------异常处理(3)

    当有一个Try块没有一个对应的异常可处理,则其父类的异常处理机制去处理。如果父类的异常处理机制不能处理,则java run-time system将会抛出一个异常。

    例子:

    class Nest{
       public static void main(String args[]){
    	 //Parent try block
         try{
        	//Child try block1
             try{
                System.out.println("Inside block1");
                int b =45/0;
                System.out.println(b);
             }
             catch(ArithmeticException e1){
                System.out.println("Exception: e1");
             }
             //Child try block2
             try{
                System.out.println("Inside block2");
                int b =45/0;
                System.out.println(b);
             }
             catch(ArrayIndexOutOfBoundsException e2){
                System.out.println("Exception: e2");
             }
            System.out.println("Just other statement");
        }
        catch(ArithmeticException e3){
        	 System.out.println("Arithmetic Exception");
             System.out.println("Inside parent try catch block");
        }
        catch(ArrayIndexOutOfBoundsException e4){
        	System.out.println("ArrayIndexOutOfBoundsException");
             System.out.println("Inside parent try catch block");
        }
        catch(Exception e5){
        	System.out.println("Exception");
             System.out.println("Inside parent try catch block");
         }
         System.out.println("Next statement..");
      }
    }
    输出:
    Inside block1
    Exception: e1
    Inside block2
    Arithmetic Exception
    Inside parent try catch block
    Next statement..


  • 相关阅读:
    python使用thrift访问操作hbase
    js打开新页面
    设计模式
    c# dotfuscator 混淆后无法使用
    SQL server清空数据库日志脚本
    SQlserver 行转列
    SQLServer 脚本测试
    C# HttpWebRequest与HttpWebResponse详解
    反射
    SQl server master
  • 原文地址:https://www.cnblogs.com/yandufeng/p/5009626.html
Copyright © 2011-2022 走看看