title: How to Rescue From An Error in Rake
body: <p>How do I rescue from a </p>
  
  <blockquote>
    <p>undefined method</p>
  </blockquote>
  
  <pre><code>error in this code
  
  for user in @users do
      @customer = Stripe::Customer.retrieve(user.stripe_customer_token)
          if @customer.subscription.nil?
          elsif @customer.subscription.plan.id == 2
            user.silver_reset
          elsif @customer.subscription.plan.id == 3
            user.gold_reset
        end
      end
  </code></pre>
  
  <p>I have tried a plain rescue call, but rake isn't liking it.</p>
  
  <p>What is way to rescue from the error?</p>
  
  <p>UPDATE:</p>
  
  <p>The way I was doing it</p>
  
  <pre><code> for    user in @users do
              @customer = Stripe::Customer.retrieve(user.stripe_customer_token)
           rescue_from Exception =&gt; exception
            # Logic
          end
          if @customer.subscription.nil?
          elsif @customer.subscription.plan.id == 2
            user.silver_reset
          elsif @customer.subscription.plan.id == 3
            user.gold_reset
        end
      end
  </code></pre>
  
  <p>The Error
  /home/user/rails_projects/assignitapp/lib/tasks/daily.rake:25: syntax error, unexpected keyword_rescue, expecting keyword_end
           rescue Exception => exception</p>
  
  <p>Rake 0.9.2.2
  Rails 3.2.5</p>