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');
}
}
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');
}
}
解决方案 »
- 求救求救Exception creating bean of class org.apache.struts.validator.DynaActionForm:
- 百度url传中文参数如何实现
- struts2下怎么把网页生成word格式的文件?
- 自己写的HttpServer---Nancy HttpServer,麻烦来看看
- 关于WEBGIS,有经验的进来看下
- java连Oracle的中文乱码问题
- hibernate里的sql
- web tomcat时区与db时区是否完全一致
- 怎么把原来的JSP发布到WEBLOGIC8.1上去了,就是怎么生成WAR,JAR文件呢
- Jbuilder如何生成一个类的stub和skeleton??????
- Timer 不知道为什么会挂起,是否和Timer在spring 环境下配置有关呢?
- 新手高分急求教JavaEE5.0项目如何更改成6.0项目
java.lang.Exception
..
java.lang.RuntimeException
..java.lang.ArithmeticException
..java.lang.IndexOutOfBoundsException
..java.lang.ArrayIndexOutOfBoundsException
java.lang.ArithmeticException
..
第二种做法时,异常未被处理,系统会中断运行,并跳出方法。
还是这边的回答比较靠谱额。。
main方法中try刚不会捕获任何异常,在mb_method()已经处理了异常,这个方法并没有抛出异常所以main方法中不会捕获到异常
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');
}
}