动手动脑:多层的异常捕获-2

运行

package demo;

public class Demo2 { 
    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

  

posted @ 2022-10-24 17:02  ashuai~  阅读(30)  评论(0)    收藏  举报