大多数 IO 操作都需要使用 try catch 块或 throws。为什么在 System.out.print 或 println 中不需要 try catch 或 throws?如果这些方法内部有任何异常,我该如何知道是什么异常以及如何捕获它。
System.out.checkError();
PrintStream.checkError()
的javadoc说:
当且仅当此流遇到除
InterruptedIOException
之外的IOException
或已调用setError
方法时,返回true
如果您真的想监视System.out
的异常,可以将自己的PrintStream
设置为System.out
并覆盖您感兴趣的方法。
catch (IOException x) { trouble = true; }
- tangens