Java: what are IOEXceptions in BufferedReader's readLine() for?

后端 未结 6 2175
说谎
说谎 2021-02-06 03:13

I can \"fix\" the below exception with a try-catch loop but I cannot understand the reason.

  1. Why does the part \"in.readLine()\" continuosly ignite IOExceptions? <
6条回答
  •  既然无缘
    2021-02-06 03:48

    IOException is a checked exception. You must either catch it, or throw it to your calling method. Checked exceptions are caused by external actors, like a missing file, failed disk or anything that you cannot recover from in your program code.

    However an Unchecked exception like ArrayIndexOutofBoundsException is caused by faulty logic in the program. You can subvert it by using an if condition outside your defective code (something like if currIndex>array.length). There is no such provision in case of checked exception

提交回复
热议问题