I'm trying to understand why printing to a closed PrintStream does not display a stream closed exception, the way FileOutputStream does.
For example, the following code does not display an exception on Eclipse's console:
public class Try {
public static void main(String[] args) {
try {
PrintStream printStream = new PrintStream(System.out);
printStream.close();
printStream.println("ABC");
} catch (Throwable t) {
System.err.println("Throwable caught");
}
}
}
Is it because the exception is happening on a separate thread? Or perhaps is PrintStream.Println defined not to throw an exception?
Edit: Non of PrintStream's methods do. Even the ones inherited from FileOutputStream, which do throw exceptions. Possibly a violation of LSP.