Which is the shortest way to silently ignore a Ruby exception
This is provided by ActiveSupport:
suppress(Exception) do # dangerous code hereend
http://api.rubyonrails.org/classes/Kernel.html#method-i-suppress
def ignore_exception begin yield rescue Exception endend
Now write you code as
ignore_exception { puts "Ignoring Exception"; raise Exception; puts "This is Ignored" }
Just wrap the left-hand side in parenthesis:
(raise RuntimeError, "foo") rescue 'yahoo'
Note that the rescue will only happen if the exception is a StandardError or a subclass thereof. See http://ruby.runpaint.org/exceptions for more info.