Must Explicitly Catch Timeout::Error

Posted on December 06, 2007
If you’re using ‘open-uri’ to pull a random URL, you might get sporadic Timeout::Error’s that are not being rescued, even if you have something like:
    begin
      @raw = open(@url)
    rescue StandardError => e
      return false, "Timeout or other Error fetching feed" 
    end

Adding an explicit rescue for the Timeout::Error did the trick. (this is due to it being a subclass of Interrupt…)

    begin
      @raw = open(@url)
    rescue StandardError => e
      return false, "Timeout or other Error fetching feed" 
    rescue Timeout::Error
      return false, "Timeout error" 
    end