以下の例外を try-catch ループで「修正」できますが、理由がわかりません。
- 「in.readLine()」の部分が継続的に IOExceptions を引き起こすのはなぜですか?
- そのような例外をスローする本当の目的は何ですか?おそらく、副作用を増やすだけではありませんか?
コードと IOExceptions
$ javac ReadLineTest.java
ReadLineTest.java:9: unreported exception java.io.IOException; must be caught or declared to be thrown
while((s=in.readLine())!=null){
^
1 error
$ cat ReadLineTest.java
import java.io.*;
import java.util.*;
public class ReadLineTest {
public static void main(String[] args) {
String s;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// WHY IOException here?
while((s=in.readLine())!=null){
System.out.println(s);
}
}
}