Saving the Error
suggest changeAssign a rescued exception to a variable when its details are needed in the handler:
def divide(x, y)
x / y
rescue StandardError => error
warn "There was a #{error.class} (#{error.message})"
warn error.full_message(highlight: false, order: :top)
nil
end
divide(10, 0) # reports ZeroDivisionError: divided by 0
divide(10, 'a') # reports TypeError: String can't be coerced into Integer
Ruby 4 uses the unified Integer class; the old Fixnum name no longer exists.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents