views:

70

answers:

1

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 an IOException other than InterruptedIOException, or the setError 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
System.out.checkError();it returns a true if there is an exception else false, how would i know which Exception.
sadananda salam
You can't find out. The exception is caught silently and the trouble flag is set: `catch (IOException x) { trouble = true; }`
tangens