我可以使用try-catch循環「修復」下面的異常,但我無法理解原因。Java:什麼是BufferedReader的readLine()中的IOEXceptions?
- 爲什麼「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);
}
}
}
太陽異常教程:http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html – BalusC 2010-04-13 13:09:42