From: "Jesús Gabriel y Galán" Date: 2011-02-12T23:32:55+09:00 Subject: Re: Exception that doesn't stop program flow On Sat, Feb 12, 2011 at 8:15 AM, Terry Michaels wrote: > Okay... this might sound weird (contradictory even) but is there a way > in Ruby to create an exception that can be caught at any level above the > point of origin, but /doesn't/ actually interrupt program flow when it > is raised? In a program I am writing, a certain sort of event occurs > that I have to be sure to deal with later on outside of the function, > but I don't want it to interrupt the function because it will leave > object data inconsistent. I probably just need to write another event > class and pop this onto some kind of global queue; but I thought I might > as well ask in case there is something helpful I have overlooked. If you have to restore the object's integrity after an exceptional event, you can use an ensure block. An ensure block is always called, after the correct execution or in light of an exception, before returning: def method puts "in the block" begin puts "in the block that raises" raise "Exception ocurred" ensure puts "restoring object integrity" end end begin method rescue puts "rescuing the exception" end Here you handle everything you need to do to safely return from the method in the ensure block, and the exception will be still raised. Jesus.