exc/exception_intercept |
Here's a neat way to intercept exceptions without rescuing them and rethrowing them (which doesn't work properly on Ruby 1.6).
E.g.:
class MyException < Exception
def initialize
super "Foo!"
end
end
exception_intercept(
proc {
raise MyException
},
proc { |exc|
case exc
when MyException
puts "Got the exception!"
else
puts "UH OH!"
kill_exception # don't let this exception propogate further
end
}
)
Public Methods |
Call main_block. If an exception is thrown, then call rescue_block. The exception will propogate automatically unless kill_exception is called.
Note that the rescue_block will be called when there is any type of exception. Using "rescue Exception" does not catch exceptions that do not inherit from class Exception.
The rescue_block will not be called when throw is used. It will not be called when continuations are used.
class KillException < Exception |