日期:2014-05-20  浏览次数:20684 次

try catch finally问题
public static int process() throws Exception {
try {
System.out.println("try"); //1
return 1; //2
} finally {
System.out.println("finally"); //3
}
}
执行流程,为什么?

public static int process() throws Exception {
try {
System.out.println("try"); //1
return 1; //2
} finally {
System.out.println("finally"); //3
return 3; //4
}
}
执行流程,为什么?

------解决方案--------------------
http://www.ticmy.com/?p=56
------解决方案--------------------
try catch finally

按顺序执行try,再执行finally,在执行try catch finally 之外代码
按顺序执行try,发生异常则执行catch 再执行finally, try catch finally以外不执行。