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

question about exception handling

 
Thomas Kijftenbelt
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question about exception handling at the network layer:
Should you always catch specific exceptions (instead of Exception)? At my network layer I catch Exception and wrap it in a subclass of runtime exception. If it is not OK to just catch Exception, I have to catch RemoteException, MalformedURLException, etc. separately - although I handle them in the same way.
At the client side I display messages based on the various causes...
Greetings,
TK
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas,
Under the circumstances you outlined I would be tempted to do the following:

How you intend to handle the exceptions should drive how you catch the exceptions. In other words if you handle all exceptions the same way you should write a catch clause that's high enough up the inheritence hierarchy that you will catch all the exceptions. In the example above, if you don't do anything special with unexpected exceptions (like logging them) then you should collapse the two cases into one and just catch Exception.
Hope this helps,
George
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic