title: Ruby each block next when exception or error is raised
body: <p>I have the following method in my rake task. </p>
  
  <pre><code>def call
    orders = Spree::Order.complete.where('completed_at &gt;= :last_day', last_day: Time.now - 30.days)
    orders.each do |order|
      order_tracking = order.shipments.first.tracking
      next if order_tracking.nil?
      shipment = order.shipments.first
      results = fedex.track(tracking_number: order_tracking)
      tracking_info = results.first
      status = tracking_info.status.to_s
      delivery_date = tracking_info.delivery_at
      shipment.is_delivered = delivered?(status)
      shipment.date_delivered = delivery_date
      shipment.save
      puts "-&gt; Shipping status was updated for #{order.number}"
    end
  end
  </code></pre>
  
  <p>If there is an order with no tracking number I skipping it with <code>next</code> on line 5. </p>
  
  <p>My question: How would I do <code>next</code> if a tracking number is invalid and the following error is raised: </p>
  
  <pre><code>Fedex::RateError: Invalid tracking number.
  </code></pre>
  
  <p>Ideally I would like to change line 5 to: </p>
  
  <pre><code>next if order_tracking.nil? || order_tracking.raised(Fedex::RateError) # something like that
  </code></pre>
  
  <p>Thank you in advance. </p>
  
  <p>Also RateError is raised here:</p>
  
  <pre><code>def process_request
    api_response = self.class.post(api_url, :body =&gt; build_xml)
    puts api_response if @debug == true
    response = parse_response(api_response)
  
    if success?(response)
      options = response[:track_reply][:track_details]
  
      if response[:track_reply][:duplicate_waybill].downcase == 'true'
        shipments = []
        [options].flatten.map do |details|
        options = {:tracking_number =&gt; @package_id, :uuid =&gt; details[:tracking_number_unique_identifier]}
        shipments &lt;&lt; Request::TrackingInformation.new(@credentials, options).process_request
        end
        shipments.flatten
      else
        [options].flatten.map do |details|
          Fedex::TrackingInformation.new(details)
        end
      end
    else
      error_message = if response[:track_reply]
                        response[:track_reply][:notifications][:message]
                      else
                        "#{api_response["Fault"]["detail"]["fault"]["reason"]}\n--#{api_response["Fault"]["detail"]["fault"]["details"]["ValidationFailureDetail"]["message"].join("\n--")}"
                      end rescue $1
      raise RateError, error_message
    end
  end
  </code></pre>