Created
March 25, 2012 15:27
-
-
Save nick-desteffen/2197335 to your computer and use it in GitHub Desktop.
Why rescue nil is bad
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
class Category < ActiveRecord::Base | |
def ask_question(question) | |
## Code to check some other system for the answer, Redis or Memcached maybe. | |
raise "System is unavailable, you should turn it on" | |
end | |
end | |
params = {category_id: 1, question: "Why did the quick brown fox jump over the lazy dog?"} | |
category = Category.find(params[:category_id]) | |
answer = category.ask_question(params[:question]) rescue nil | |
if answer | |
## Do something with the answer | |
else | |
## Do something else | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment