-
Notifications
You must be signed in to change notification settings - Fork 6
Exception Handling in Tim
Contributers please follow this guide for handling errors and exceptions in Tim.
Swallowing exceptions is generally bad practice, however, there are times when swallowing an exception is a perfectly reasonable thing to do. These scenarios should be infrequent, if you are swallowing a lot of exceptions then it usually means you are not following this guide properly.
If you are creating a method that expects some exception (or an exception is a valid expectation) then you are safe to catch the exception and not log it (i.e. Swallow it). These scenarios should be infrequent. One example of an appropriate time to swallow could be something like as follows:
def can_connect_to_imagefactory?
begin
Tim::TargetImage.find(1)
rescue ActiveResource::ConnectionError
false
end
true
end
In the above method an ActiveResource::ConnectionError is expected when the server is unable to connect. There is no need in this case to log the error or raise it. When is swallowing an exception not appropriate?