动手动脑

11.3

多层的异常捕获:

代码部分:

package lianxi;
import javax.swing.*;
public class bo {

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");
}
}
}

 运行结果:

运行结果分析:

捕获了内层的try catch

原文地址:https://www.cnblogs.com/092e/p/14146343.html