aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/rescuable.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/rescuable.rb')
-rw-r--r--activesupport/lib/active_support/rescuable.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb
index dc3f27a16d..7f29c955f9 100644
--- a/activesupport/lib/active_support/rescuable.rb
+++ b/activesupport/lib/active_support/rescuable.rb
@@ -74,7 +74,7 @@ module ActiveSupport
#
# If no handler matches the exception, check for a handler matching the
# (optional) exception.cause. If no handler matches the exception or its
- # cause, this returns nil so you can deal with unhandled exceptions.
+ # cause, this returns +nil+, so you can deal with unhandled exceptions.
# Be sure to re-raise unhandled exceptions if this is what you expect.
#
# begin
@@ -83,16 +83,18 @@ module ActiveSupport
# rescue_with_handler(exception) || raise
# end
#
- # Returns the exception if it was handled and nil if it was not.
+ # Returns the exception if it was handled and +nil+ if it was not.
def rescue_with_handler(exception, object: self)
- if handler = handler_for_rescue(exception, object: object)
+ handler, exception = handler_for_rescue(exception, object: object)
+ if handler
handler.call exception
exception
end
end
def handler_for_rescue(exception, object: self) #:nodoc:
- case rescuer = find_rescue_handler(exception)
+ rescuer, exception = find_rescue_handler(exception)
+ result = case rescuer
when Symbol
method = object.method(rescuer)
if method.arity == 0
@@ -107,6 +109,7 @@ module ActiveSupport
-> e { object.instance_exec(e, &rescuer) }
end
end
+ [result, exception]
end
private
@@ -121,7 +124,11 @@ module ActiveSupport
end
end
- handler || find_rescue_handler(exception.cause)
+ if handler
+ [handler, exception]
+ else
+ find_rescue_handler(exception.cause)
+ end
end
end