锤子智能手机操作系统发布会 [zz]
发表回复
public class ExceptionTest {
public static void main(String[] args) {
String s = null;
try {
s = genString(true);
} finally {
System.out.println(s);
}
}
private static String genString(boolean throwEx) {
try {
if (throwEx) {
throw new RuntimeException("Exception");
}
System.out.println("in try");
return "no exception";
} catch (Exception ex) {
System.out.println("in catch");
return "exception";
} finally {
System.out.println("in finally");
return "finally";
}
}
}
其中genString(boolean)可以决定是否抛异常,在“true”时会打印什么?或者说,genString方法究竟会执行哪条return?传入“false”呢? 阅读全文