验证try中return,finally中是否执行
package com.jiucheng;
/**
* testTryCatch
*
* @auther qiaoba
* @date 2020/9/18 0018 9:25
**/
public class testTryCatch {
public static void main(String[] args) {
int method = method();
System.out.println(method);
}
public static int method(){
int a = 0;
try {
System.out.println("执行了try代码体...................");
int b = 10/0;
return a;
}catch (Exception e){
a++;
System.out.println("执行了catch代码体...............");
}finally {
a+=2;
System.out.println("执行了finally代码体");
}
return a;
}
}
执行返回结果为: