Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IOException vs FileNotFoundException

 
jean-gobert de coster
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Is there any particular reason why instantiating a new FileWriter throws an IOException while instantiating a new PrintWriter throws a FileNotFoundException?

edit: oh and also, why don't the close() and flush() methods throw an IOException in PrintWriter while they do in FileWriter and BufferedWriter ?
[ December 16, 2008: Message edited by: jean-gobert de coster ]
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think FileWriter is low-level writer and designed very early of the java production, so developers would have decided to propagate the exception upto the use to handle explicitly, that's why flush(), close(), write() throws exception.

And PrintWriter is very high level writer, it is known for easy to use. That's why they would have handled these execeptions in the methods itself instead of propagating. I donot think there any big issue to design this way. I think first they propagated the exception, but after some time they could have found handling them will provide more cleaner API, so...

All IO methods have exception, but in some they are handled in them, in some they are thrown.

Any sheriff could tell us about that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic