Published about 6 years ago
In Rails 2.2, controller’s rescue_from has been extracted to ActiveSupport as ActiveSupport::Rescuable module. Relevant commits are 964dfc and 259a7a. This allows you to use rescue_from functionality in class as a cleaner way of handling exceptions.
Now you can just include ActiveSupport::Rescuable in your class and start using rescue_with_handler(exception) from your rescue blocks :
class Armageddon < StandardError end class Earth include ActiveSupport::Rescuable rescue_from Armageddon, :with => :nuke_the_rock def life raise Armageddon rescue Exception => e rescue_with_handler(e) end def nuke_the_rock puts "snafu" end end e = Earth.new e.life
The above code will produce output “snafu”. You can also check code/docs if you wanna know more.