Skip to content

Instantly share code, notes, and snippets.

@nick-desteffen
Created March 25, 2012 15:27
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 nick-desteffen/2197335 to your computer and use it in GitHub Desktop.
Save nick-desteffen/2197335 to your computer and use it in GitHub Desktop.
Why rescue nil is bad
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