当前位置: 代码迷 >> J2SE >> try catch finally有关问题
  详细解决方案

try catch finally有关问题

热度:6985   发布时间:2013-02-25 00:00:00.0
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以外不执行。