Rescuable module adds support for easier exception handling.
# File lib/active_support/rescuable.rb, line 84 84: def handler_for_rescue(exception) 85: # We go from right to left because pairs are pushed onto rescue_handlers 86: # as rescue_from declarations are found. 87: _, rescuer = self.class.rescue_handlers.reverse.detect do |klass_name, handler| 88: # The purpose of allowing strings in rescue_from is to support the 89: # declaration of handler associations for exception classes whose 90: # definition is yet unknown. 91: # 92: # Since this loop needs the constants it would be inconsistent to 93: # assume they should exist at this point. An early raised exception 94: # could trigger some other handler and the array could include 95: # precisely a string whose corresponding constant has not yet been 96: # seen. This is why we are tolerant to unknown constants. 97: # 98: # Note that this tolerance only matters if the exception was given as 99: # a string, otherwise a NameError will be raised by the interpreter 100: # itself when rescue_from CONSTANT is executed. 101: klass = self.class.const_get(klass_name) rescue nil 102: klass ||= klass_name.constantize rescue nil 103: exception.is_a?(klass) if klass 104: end 105: 106: case rescuer 107: when Symbol 108: method(rescuer) 109: when Proc 110: rescuer.bind(self) 111: end 112: end
Tries to rescue the exception by looking up and calling a registered handler.
# File lib/active_support/rescuable.rb, line 77 77: def rescue_with_handler(exception) 78: if handler = handler_for_rescue(exception) 79: handler.arity != 0 ? handler.call(exception) : handler.call 80: true # don't rely on the return value of the handler 81: end 82: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.