《Cracking the Coding Interview》——第14章:Java——题目2
2024-08-26 00:02:21
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.");
}
}
}
最新文章
- 由LazyMan联想到的
- python多线程下载
- 使用AIDL将接口暴露给客户端(远程绑定Service)
- poj 2192 (DP)
- HttpGet和HttpPost
- String s=new String(";abc";)创建了几个对象?
- SQL执行计划分析
- Linux进阶命令用法
- simple shell
- 167. Two Sum II - Input array is sorted (Array)
- c166 -div
- vue 学习1
- android与JS交互,互相调用方法,跳转到网页
- JAVA实现zip压缩需要注意的问题
- JS设置localStorage有效期
- python 迭代器 和生成器
- WPF中DataGrid控件的过滤(Filter)性能分析及优化
- Newtonsoft.Json之JArray, JObject, JProperty,JValue
- informix 把数据从一个表倒到另外一个表中
- SOA架构,dubbo,Zookeeper
热门文章
- API:什么是API?API与interface的区别
- bzoj3882 [Wc2015]K小割
- DP找最优配置,(POJ1018)
- IOError: [Errno 22] invalid mode ('rb') or filename: 'F:\netData1.mat'
- 旧文备份: CANopen的LSS子协议中文翻译
- caffe中protobuf问题
- 判断一个Object是否为数组Array的方法
- linux 设置自动关机和重启命令shutdown
- spring cloud 学习之服务消费者(rest+ribbon)
- input标签中的name