异常练习
11.4
代码练习:
package lianxi;
import javax.swing.*;
public class bo {
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");
}
}
}
运行结果:
运行结果分析:
捕获了外层的try catch