Name: dbT83986 Date: 02/22/99
The problem is, that if you use the constructor PrintWriter(Writer) of the class PrintWriter with a PrintWriter as argument the method
checkError() will fail. This is, because in checkError() the method flush() is called. If flush() throws an IOException the instance
variable trouble is set to true. Now PrintWriters never throws an IOException when you flush them. This means that if you encapsulate a
PrintWriter in another PrintWriter checkError() will never return true, even if there was an error.
public class Test {
public void main(String[] args) throws Exception {
File OutputStream out = new FileOutputStream("somefile");
PrintWriter pw1 = new PrintWriter(out);
PrintWriter pw2 = new PrintWriter(pw1);
out.close();
pw2.println("blabla");
System.out.println(pw2.checkError());
}
}
(Review ID: 47349)
======================================================================
The problem is, that if you use the constructor PrintWriter(Writer) of the class PrintWriter with a PrintWriter as argument the method
checkError() will fail. This is, because in checkError() the method flush() is called. If flush() throws an IOException the instance
variable trouble is set to true. Now PrintWriters never throws an IOException when you flush them. This means that if you encapsulate a
PrintWriter in another PrintWriter checkError() will never return true, even if there was an error.
public class Test {
public void main(String[] args) throws Exception {
File OutputStream out = new FileOutputStream("somefile");
PrintWriter pw1 = new PrintWriter(out);
PrintWriter pw2 = new PrintWriter(pw1);
out.close();
pw2.println("blabla");
System.out.println(pw2.checkError());
}
}
(Review ID: 47349)
======================================================================