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
posted 13 years ago
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
SCJP, SCJD, SCWCD, SCBCD
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads