另一个原因是System.out和err是PrintStreams,它们消耗所有底层IOExceptions。 请参阅PrintStreams的这种方法:
/**
* Writes the specified byte to this stream. If the byte is a newline and
* automatic flushing is enabled then the flush method will be
* invoked.
*
*
Note that the byte is written as given; to write a character that
* will be translated according to the platform's default character
* encoding, use the print(char) or println(char)
* methods.
*
* @param b The byte to be written
* @see #print(char)
* @see #println(char)
*/
public void write(int b) {
try {
synchronized (this) {
ensureOpen();
out.write(b);
if ((b == '\n') && autoFlush)
out.flush();
}
}
catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
}
catch (IOException x) {
trouble = true;
}
}
/**
* Flushes the stream and checks its error state. The internal error state
* is set to true when the underlying output stream throws an
* IOException other than InterruptedIOException,
* and when the setError method is invoked. If an operation
* on the underlying output stream throws an
* InterruptedIOException, then the PrintStream
* converts the exception back into an interrupt by doing:
*
* Thread.currentThread().interrupt();
*
* or the equivalent.
*
* @return true if and only if this stream has encountered an
* IOException other than
* InterruptedIOException, or the
* setError method has been invoked
*/
public boolean checkError() {
if (out != null)
flush();
if (out instanceof java.io.PrintStream) {
PrintStream ps = (PrintStream) out;
return ps.checkError();
}
return trouble;
}
因此,总是消耗来自底层流的IOException,并且通常人们从不在System out上调用checkError,因此他们甚至不知道发生了什么。