Java unreachable catch block compiler error

后端 未结 6 1076
孤城傲影
孤城傲影 2020-11-27 06:25

Why in Java can we catch an Exception even if it is not thrown, but we can\'t catch it\'s subclass (except for \"unchecked\" RuntimeExceptions and

6条回答
  •  孤城傲影
    2020-11-27 07:13

    IO Exceptions can only be caught if the compiler predicts that there might be something in the code that throws IOException. So you are getting a warning that IO exception is never thrown from the try statement body (since there is nothing in the body of try).

提交回复
热议问题