Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Question - antipattern

 
Michael Kelleher
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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?
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic