public class Test2 {
public static void main(String args[]) {
System.out.println(method());
}
public static int method() {
try {
throw new Exception();
return 1;
} catch (Exception e) {
return 2;
} finally {
return 3;
}
}
}
try块抛出有return语句,并抛出异常也... 其输出为编译器错误....return语句,并在Java
我们知道,finally块覆盖try/catch块中的返回值或异常声明... 但这个问题已经在try块中... 为什么输出错误?
你介意与我们分享实际的编译器错误吗?虽然这是一个相当平凡的案例,但通常情况下,通过发布不完整/不明确的问题,可以减少获得良好答案的机会。 – 2010-09-21 08:30:39