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

运行

package demo;

public class Demo2 { 
    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
posted @ 2022-10-24 17:00  ashuai~  阅读(26)  评论(0)    收藏  举报