I'm using Eclipse, it give me a compilation error when i use this Code
Unreachable catch block for IOException. This exception is never thrown from the try statement body
public void f() {
try {
System.out.println("");
} catch (IOException e) {
// TODO: handle exception
}
}
but when i use Exception instead of IOException it compile, both are checked exceptions, waht am i doing wrong
catch (Exception e)is a special case in the Java Language Specification. The rule iscatch (IOException e)can only catchIOExceptionand its subclasses, which are all checked exceptions.On the other hand,
catch (Exception e)can catchRuntimeExceptionand its subclasses (among other things), which are not checked exceptions. Therefore, it cannot be concluded that thecatchblock will never be executed.