首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

初学JAVA到错误这里,有个有关问题想问

2012-01-15 
初学JAVA到异常这里,有个问题想问!packagemy.javaimportstaticjava.lang.System.outpublicclassCatchWho

初学JAVA到异常这里,有个问题想问!
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异常呢?

[解决办法]
因为你这个属于一个try catch
它捕获到一个就结束跳出了
所以第一个throw new ArrayIndexOutOfBoundsException();
抓住就结束了
[解决办法]
抓住一个异常就会不 执行其它的代码了

热点排行
Bad Request.