如果try.........catch....里面有return语句,请问finally的代码还会执行吗?
如果会,请问是在return前还是return后? 具体如下代码,请问返回的X是多少?
public class ExceptionTest2 {
public static void main(String[] args) {
int result = method2(10);
System.out.println(result);
//System.out.println("结束了");
}
private static int method2(int x) {
try{
System.out.println(x/0);
} catch (ArithmeticException e) {
System.out.println("异常产生了");
return x;
} finally {
System.out.println("解决异常了");
x++;
}
return 0;
}
|
|