Java exception try-catch Exception vs IOException -
Java exception try-catch Exception vs IOException -
this question has reply here:
java unreachable grab block compiler error 6 answersthe next code compiles ok though seek block doesn't throw exception.
public static void main(string[] args) { seek {} grab (exception e) {} // compiles ok }
but if grab replaced sub-class of exception, code won't compile.
public static void main(string[] args) { seek {} grab (ioexception e) {} // won't compile. }
the compiler error is: unreachable grab block ioexception. exception never thrown seek statement body.
how come behavior when both exception & ioexception checked exceptions? i'm using java 7.
the compiler can know part of code can throw ioexception
because checked exception, every method can throw kind of exception must specify in method signature.
on other hand, runtime or unchecked exceptions not meant expected, , since runtimeexception
(the parent class of unchecked exceptions) extends class exception
, compiler ok it.
java exception
Comments
Post a Comment