title: Ruby on Rails Error Handling, Catching Error and Message
body: <p>I'm trying to figure out the best way to catch a specific error thrown AND the error's message in Ruby on Rails. My use case is that I encounter a timeout error every now and then which is thrown with a general error and I want to treat the timeout error differently than other errors within the same general error. I'm not sure what other type of errors could be thrown in the general error but I assume more of them exist. I have some sample code below of how I'm currently handling it, but I was thinking there might be a better way which I haven't found yet?</p>
  
  <pre><code>tries = 0
  begin
    tries += 1
    &lt;code&gt;
  rescue Foo::Bar =&gt; e
    case e.to_s
    when 'More specific timeout error message'
      retry unless tries &gt;= 5
    else
      # Let me see other error messages
      log.info("Error: #{e.to_s}")
    end
  end
  </code></pre>