Der folgende Code kompiliert ok, obwohl der try-Block tatsächlich keine Ausnahme auslöst.Java-Ausnahme try-catch Ausnahme vs IOException
Wenn der Catch jedoch durch eine Unterklasse von Exception ersetzt wird, wird der Code nicht kompiliert.
public static void main(String[] args) {
try {}
catch (IOException e) {} // won't compile.
}
Der Compiler Fehler ist: nicht erreichbar Fangblock für IOException. Diese Ausnahme wird niemals aus dem Körper der try-Anweisung ausgelöst.
Wie kommt dieses Verhalten, wenn beide Ausnahmen & IOException sind Ausnahmen überprüft? Ich bin mit Java 7.
'RuntimeException's sind auch' Exceptions', also sind nicht alle Exceptions geprüft. –