Skip to content

Instantly share code, notes, and snippets.

@jaydorsey
Last active April 2, 2021 21:43
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 jaydorsey/609c83db5d3054c227706a7acad450c6 to your computer and use it in GitHub Desktop.
Save jaydorsey/609c83db5d3054c227706a7acad450c6 to your computer and use it in GitHub Desktop.
Customer errors with an argument
# Custom errors with arguments
#
# Example usage:
#
# ENV.fetch('BLAH') { raise EnvironmentError.new('BLAH') }
class EnvironmentError < StandardError
attr_reader :key
def initialize(key)
@key = key
end
def message
"A required ENV key, #{key}, is missing. Check the README"
end
end
@jaydorsey
Copy link
Author

A good example here via here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment