finally语句后面的语句到底会不会执行,什么情况下会执行呢//代码换成注释后的输出也不理解- -
public class J_Test {
public static void mb_createException()
{
    throw new ArrayIndexOutOfBoundsException();
}public static void mb_method()
{
    try
    {
        mb_createException();
        System.out.print("a");
    }
    catch (Exception e)//第二种做法:Exception换成ArithmeticException
    {
        System.err.print("b");
    }
    finally
    {
        System.out.print("c");
    }
    System.out.print("d");//为什么第二种做法的时候,这句没有被执行???
}
public static void main(String args[])
{
    try
    {
        mb_method();
    }
    catch (ArithmeticException e)//第二种做法:ArithmeticException换成Exception
    {
        System.err.print('m');
    }
    finally
    {
    System.out.print('n');
    }
    System.out.print('x');
}
    
}

解决方案 »

  1.   

    看下API的异常分类
    java.lang.Exception
      ..
      java.lang.RuntimeException
      ..java.lang.ArithmeticException
      ..java.lang.IndexOutOfBoundsException
        ..java.lang.ArrayIndexOutOfBoundsException
      java.lang.ArithmeticException
      ..
      

  2.   

    第一种做法时,异常被处理,系统会在try 范围外的下一步开始运行。
    第二种做法时,异常未被处理,系统会中断运行,并跳出方法。
      

  3.   

    finally语句块无论如何都会被执行的,另,LZ在看一下异常的的分类结构!
      

  4.   

    http://topic.csdn.net/u/20110325/13/8941c622-52fb-45fa-863a-8c9672d2fe8b.html?seed=1010037020&r=72380261#r_72380261
    还是这边的回答比较靠谱额。。
      

  5.   

    只会输出bcdx第一个try正常运行catch与finally都输出正常,
    main方法中try刚不会捕获任何异常,在mb_method()已经处理了异常,这个方法并没有抛出异常所以main方法中不会捕获到异常
      

  6.   

    //譬如下面代码的输出 运行结果会改变的 有时候mcnx,有时候又cnxm  请问这是怎么回事呀?public class J_Test {
    public static void mb_createException()
    {
    throw new ArrayIndexOutOfBoundsException();
    }public static void mb_method()
    {
    try 
    {
    mb_createException();
    System.out.print("a");
    }
    catch (ArithmeticException e)//(Exception e)
    {
    System.err.print("b");
    }
    finally
    {
    System.out.print("c");
    }
    System.out.print("d");
    }
    public static void main(String args[])
    {
    try
    {
    mb_method();
    }
    catch (Exception e)//(ArithmeticException e)
    {
    System.err.print('m');
    }
    finally
    {
    System.out.print('n');
    }
    System.out.print('x');
    }

    }