package my.java;
import static java.lang.System.out;public class CatchWho2
{
public static void main(String[] args)
{
try
{
try
{
throw new ArrayIndexOutOfBoundsException();
}
catch(ArithmeticException e)
{
out.println("Trigger a ArithmeticException...Inner...");
}
throw new ArithmeticException();
}
catch(ArithmeticException e)
{
out.println("Trigger a ArithmeticException...Outer");
}
catch(ArrayIndexOutOfBoundsException e)
{
out.println("Trigger a ArrayIndexOutOfBoundsException...Outer");
}
}
}为什么只捕获了一个ArrayIndexOutOfBoundsException异常?
而不捕获ArithmeticException异常呢?
import static java.lang.System.out;public class CatchWho2
{
public static void main(String[] args)
{
try
{
try
{
throw new ArrayIndexOutOfBoundsException();
}
catch(ArithmeticException e)
{
out.println("Trigger a ArithmeticException...Inner...");
}
throw new ArithmeticException();
}
catch(ArithmeticException e)
{
out.println("Trigger a ArithmeticException...Outer");
}
catch(ArrayIndexOutOfBoundsException e)
{
out.println("Trigger a ArrayIndexOutOfBoundsException...Outer");
}
}
}为什么只捕获了一个ArrayIndexOutOfBoundsException异常?
而不捕获ArithmeticException异常呢?
它捕获到一个就结束跳出了
所以第一个throw new ArrayIndexOutOfBoundsException();
抓住就结束了