Last active
April 2, 2021 21:43
-
-
Save jaydorsey/609c83db5d3054c227706a7acad450c6 to your computer and use it in GitHub Desktop.
Customer errors with an argument
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A good example here via here