當我使用下面的代碼,編譯錯誤發生。好奇,是否條件和例外
try {
throw new Exception("Exceptionist");
System.out.println("another line"); //compilation error
}catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
編譯錯誤的原因是我們不能在拋出異常後編寫代碼。 但是,當我嘗試這樣的事情
try {
if (true)
throw new Exception("Exceptionist");
System.out.println("another line"); // no compilation
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
即使在Eclipse IDE預測syso死代碼,爲什麼不是Java點出來。即使它被編譯成字節碼,syso也不會被執行。那麼爲什麼它不被視爲編譯錯誤。 (我知道它不是一個編譯錯誤:|。可能是,表示它的一些其他方式)它是給程序員的選擇嗎?