• 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

Exception Question - antipattern

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read the thread on the Exception antipattern. I was wondering if anyone could see a potential problem with swallowing an IOException when closing a InputStream or OutputStream? I have utility methods that close these, and swallow the Exception. The thought being, that this should mostly never happen, they should not prohibit the application from functioning.

What do you think?
 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael,


The thought being, that this should mostly never happen, they should not prohibit the application from functioning.



Yes this is true, "this should mostly never happen", but when it happens you lost the possibility of handle the exception and maybe later this cause a NullPointerException or another exception unexpected for you (and more difficult to track), it looks for me like the "Catch and Ignore" antipattern, it says:


Catch and Ignore

Example:



This one is insidious. Not only does it return null instead of handling or re-throwing the exception, it totally swallows the exception, losing the information forever.



from:

Exception handling antippaterns

I hope it helps you.

[ September 03, 2007: Message edited by: Gabriel Vargas ]
[ September 03, 2007: Message edited by: Gabriel Vargas ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic