2014-04-26 18:44

题目:在java的try-catch-finally语句块里,如果catch里面有return语句的话,finally还会被执行吗?

解法:会。

代码:

 // 14.2 Will the code in finally {} be executed if there is a return statement inside try {} or catch{}?
// The answer is yes.
// OUTPUT:
// Hello world.
// An exception is caught: java.lang.ArrayIndexOutOfBoundsException: 2
// Finally you're here.
public class TestJava {
public static void main(String[] args) {
try {
System.out.println("Hello world.");
int[] a = new int[2];
a[2] = 1;
return;
} catch (Exception e) {
// TODO: handle exception
System.out.println("An exception is caught: " + e);
return;
} finally {
System.out.println("Finally you're here.");
}
}
}

最新文章

  1. 由LazyMan联想到的
  2. python多线程下载
  3. 使用AIDL将接口暴露给客户端(远程绑定Service)
  4. poj 2192 (DP)
  5. HttpGet和HttpPost
  6. String s=new String("abc")创建了几个对象?
  7. SQL执行计划分析
  8. Linux进阶命令用法
  9. simple shell
  10. 167. Two Sum II - Input array is sorted (Array)
  11. c166 -div
  12. vue 学习1
  13. android与JS交互,互相调用方法,跳转到网页
  14. JAVA实现zip压缩需要注意的问题
  15. JS设置localStorage有效期
  16. python 迭代器 和生成器
  17. WPF中DataGrid控件的过滤(Filter)性能分析及优化
  18. Newtonsoft.Json之JArray, JObject, JProperty,JValue
  19. informix 把数据从一个表倒到另外一个表中
  20. SOA架构,dubbo,Zookeeper

热门文章

  1. API:什么是API?API与interface的区别
  2. bzoj3882 [Wc2015]K小割
  3. DP找最优配置,(POJ1018)
  4. IOError: [Errno 22] invalid mode ('rb') or filename: 'F:\netData1.mat'
  5. 旧文备份: CANopen的LSS子协议中文翻译
  6. caffe中protobuf问题
  7. 判断一个Object是否为数组Array的方法
  8. linux 设置自动关机和重启命令shutdown
  9. spring cloud 学习之服务消费者(rest+ribbon)
  10. input标签中的name