//异常的处理,执行流程!
public class Demo_Finally {
public static void main(String[] args) {
Demo_Finally df = new Demo_Finally();
//df.foo(1); //23
df.foo(2); //134
System.out.println(df.output);//分别运行上面的两行代码,请分析输出结果分别是?
//打印的是成员变量
}
public String output = "";
public void foo(int i) { //不需要返回值void
try {
if (i == 1) {
throw new Exception();
}
output += "1";
} catch (Exception e) {
output += "2";
return;
} finally {
output += "3";
}
output += "4";
}
}
|
|