Java中的try/catch/finally
2024-08-20 17:08:13
样例1:
public class Test{
public static String output = "";
public static void foo(int i){
try{
if(i == 1){
throw new Exception();
}
}catch(Exception e){
output += "2";
return ;
}finally{
output += "3";
}
output += "4";
} public static void main(String[] args){
foo(0);
foo(1);
System.out.println(output);
}
}
输出:3423
说明:try之后并定执行finally,finally如果没有返回,则会继续执行下面的代码
样例2:
public class Test{
public static String output = "";
public static void foo(int i){
try{
if(i == 1){
throw new Exception();
}
}catch(Exception e){
output += "2";
}finally{
output += "3";
}
output += "4";
} public static void main(String[] args){
foo(0);
foo(1);
System.out.println(output);
}
}
输出:34234
最新文章
- 配置nginx好了,html能打开,index.php打不开?
- 【问题&;解决】试用版SQL Server 2008 R2 提示评估期已过,数据库不能访问解决办法
- 最长回文子串Manacher算法模板
- java的重修之路
- JavaScript中定时器
- Android4.2.2的Stagefright维护编解码器的数据流
- Bzoj1479: [Nerrc1997]Puncher打孔机
- 二分查找c++简单模板
- js 原型规则与示例
- LongAdder基础
- Highgo 瀚高数据库的简单搭建以及处理参数等.
- LOJ2250 [ZJOI2017] 仙人掌【树形DP】【DFS树】
- MySQL最优配置模板( 5.6&;5.7)(运维那点事)
- S5PV210 PWM定时器
- LSTM介绍
- BZOJ4239 : 巴士走读
- linux常用命令:du 命令
- Kindle一周使用感受
- 17monipdb.dat
- maven 服务器搭建 -- nexus