• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IOException vs FileNotFoundException

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic