Java: what are IOEXceptions in BufferedReader's readLine() for?
Posted
by HH
on Stack Overflow
See other posts from Stack Overflow
or by HH
Published on 2010-04-13T12:58:17Z
Indexed on
2010/04/13
13:12 UTC
Read the original article
Hit count: 397
I can "fix" the below exception with a try-catch loop but I cannot understand the reason.
- Why does the part "in.readLine()" continuosly ignite IOExceptions?
- What is really the purpose of throwing such exceptions, the goal probably not just more side effects?
Code and 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);
}
}
}
© Stack Overflow or respective owner