On Sat, Feb 12, 2011 at 2:15 AM, Terry Michaels <cmhoward / frigidcode.com> 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?
There are a few ways to do this. One way to return side-band data like
this is to set a thread-local variable and check its value later on. A
clean-ish way to do this is to make a method that encapsulates the
error check:
def handle_errors
yield
if Thread.current[:error]
# handle error
Thread.current[:error] = nil
end
end
handle_errors do
# ... code that might set the error flag ...
end
--
Avdi Grimm
http://avdi.org