行 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 のコメントを外すと、'unreachable statement' コンパイル時エラーが発生します。
なぜコンパイラがそれほど一貫性がないのだろうか...