package com.jiben.Test;public class J_Test1 {
public static void main(String[] args){
try{
System.out.println("1");
if(true)
return;
}
catch(RuntimeException e1){
System.out.println("2");
return;
}
catch(Exception e2){
System.out.println("3");
return;
}
finally{
System.out.println("4");
}
System.out.println("End!");
}
}为何 End!没有输出 请高收解释
public static void main(String[] args){
try{
System.out.println("1");
if(true)
return;
}
catch(RuntimeException e1){
System.out.println("2");
return;
}
catch(Exception e2){
System.out.println("3");
return;
}
finally{
System.out.println("4");
}
System.out.println("End!");
}
}为何 End!没有输出 请高收解释
解决方案 »
- java.lang.NullPointerException。 是否是Spring配置的问题? 谢谢!
- 关于Struts action之间redirect跳转,数据传递的问题
- ofbiz 发布到 weblogic 类型
- struts1.2中的validate框架验证问题
- dom4j读写XML文件问题(eclipse环境)
- Eclipse 中开发 Apache Derby 应用程序
- action报错:No result defined for action and result error
- 我用hotmail的帐号,JAVAMAIL进行发送,为什么会失败???实在是不解
- 安装weblogic,是不是设置系统的administrator环境变量比较好啊?
- 为什么我配的J2EE1.3的DukesBank不能正常工作?
- STRTUS2中的数据TRIM的问题
- 大家好~~~帮我看一下一个配置问题~~我相信你们都遇到过~~谢谢~~~
System.out.println("1");
之后if true ,然后就执行finally里的System.out.println("4");
然后
就跑到return去了,当然不会执行end了
try后总是要执行finally中的语句块
打印结果就是
1
4如果catch了,就有在catch中语句块return出,再执行 finally 中语句块
只有一种情况finally语句块不执行:受保护代码(try语句块中的代码)中调用System。exit()强行终止程序。如果try语句块或者catch语句块中有return语句,都会首先执行finally语句块的内容然后再执行return语句。
1
4
然后 return
后面的代码不会被执行的
至于finally,一般是用来释放一些必须要释放的资源时用,在finally里的语句不管是否出错都会执行。
主要的就是这样的。