Skip to content

Instantly share code, notes, and snippets.

@deepak
Created June 27, 2012 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepak/3004559 to your computer and use it in GitHub Desktop.
Save deepak/3004559 to your computer and use it in GitHub Desktop.
thrown error picks message over to_s
# message is shown over to_s (not checked for inspect)
# when an error is raised
class DefaultError < StandardError
def message
"default-message"
end
end
class SameMessageError < DefaultError
end
class SpecificError < DefaultError
alias :message :to_s
end
f = SameMessageError.new "specific-message"
# raise f #default-message is shown and NOT specific-message
f = SpecificError.new "specific-message"
raise f #specific-message is shown this time and NOT default-message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment