• Post Reply Bookmark Topic Watch Topic
  • New Topic

PrintWrite close() does not catches Exception  RSS feed

 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,I am trying to write text to a file. Initially, i was using BufferedWriter, but that however was writing all lines in one line. Now i changed it to PrintWriter to write using println(line) method.
When i calling close() method it does not catches an IOException. API also says that it does catches. Can i leave without - i am not sure.
Here is the code.


With BufferedWriter it does catch
 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, this is the error message:
exception java.io.IOException is never thrown in body of corresponding try statement
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler knows these things -- you can trust it!

The Javadoc for PrintWriter does indeed show that PrintWriter.close() (along with most other PrintWriter methods) does not throw IOException.
 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do i need to use checkError() method at all instead?

Or as you noted, just leave it to a compiler.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!