On Nov 8, 2007, at 3:04 PM, Alex D. wrote:
I’m write a wrapper for a web service and am wondering about the best
way to handle exceptions.
The main method in the wrapper sends either a HEAD or GET request to a
web server using Net::HTTP.
Should I catch any exceptions thrown by Net::HTTP and then throw back
my own exception, or should I leave the exceptions totally un-handled?
i generally do one of two things
a) let the exception pass through. this is ok if, and only if, there
is nothing reasonable your code could do to retry. if you do retry
you have you have a configurable numbmer of retries, of course.
b) wrap the errors. my preferred approach is something like
class Error < ::StandardError
def self.wrapping exception, *a, &b
e = new *a, &b
e.exception = exception
class Specific < Error; end
class EvenMoreSpecific < Specific; end
this allows client code respond appropriately to specific errors or
simply to rescue the entire class of errors your wrapper might throw
and, when you want to wrap another error you can
rescue => e
i would say that you have to have a good reason to pick b over a, but
they do exist.
a @ http://codeforpeople.com/