public class Test{
public int add(int a,int b){
try {
return a+b;
}
catch (Exception e) {
System.out.println("catch语句块");
}
finally{
System.out.println("finally语句块");
}
return 0;
}
public static void main(String argv[]){
Test test =new Test();
System.out.println("和是:"+test.add(9, 34));
}
}
执行顺序
- try语句中return(包含return中的代码)前的代码
- 无异常进入finally语句
- 最后执行try中return
- 输出“finally语句块 和是:43
try catch finally执行顺序具体https://blog.csdn.net/MiaoWei_/article/details/109198951?utm_source=app&app_version=5.4.0