第 2 行的语句永远不会执行,但编译器不会抱怨:
class Test {
public static void main(String[] args) throws Exception {
throwE();
// throw new Exception(); // Line 1
doStuff(); // Line 2
}
static void throwE() throws Exception {
System.out.println("Throwing an Exception");
throw new Exception();
// doStuff(); // Line 3
}
static void doStuff(){ System.out.println("Doing stuff"); }
}
另一方面,取消注释第 1 行或第 3 行会导致“无法访问的语句”编译时错误。
我想知道为什么编译器如此不一致......