Most of the IO operation requires try catch block or throws . Why is try catch or throws not required for System.out.print or println. If there is any exception inside these methods how would i know whats the exception and how to catch it.
+2
A:
You can check for an error by calling
System.out.checkError();
javadoc of PrintStream.checkError()
says:
returns
true
if and only if this stream has encountered anIOException
other thanInterruptedIOException
, or thesetError
method has been invoked
If you really want to monitor exceptions of System.out
you could set your own PrintStream
to System.out
and override the methods you are interested in.
tangens
2010-10-02 17:54:11
System.out.checkError();it returns a true if there is an exception else false, how would i know which Exception.
sadananda salam
2010-10-02 17:58:52
You can't find out. The exception is caught silently and the trouble flag is set: `catch (IOException x) { trouble = true; }`
tangens
2010-10-02 18:01:11