Trying and salvation serve different purposes. The goal of try is to save you the need:
if user && user.email
Or any situation where the parent can be zero, which raises a NoMethodError on a NilClass. The goal of rescue is to handle exceptions that are thrown by a method call. If you expect the exception to be thrown by user.email , you can rescue nil to prevent it, so that the exception does not happen.
In general, I would say avoid using rescue nil unless you know exactly which exceptions you are saving, because you can save another exception, and you will never know about it because rescue nil prevent you from seeing it. At least, maybe you can register it:
begin ...some code... rescue => ex logger.error ex.message end
Jack Chu May 19 '11 at 18:49 2011-05-19 18:49
source share