I’ve got a rake task that includes a section where I do something like this:
begin # Do some things rescue => ex puts "Error: #{ex}" end </pre>
I know that typically you want to be specific about the errors that you catch, but in this case I just want to move on. The things that didn't happen on this pass will get caught the next time around. It turns out that this code block won't always catch every error. It took some serious thinking to figure out why. Network time out errors are not a subclass of StandardError and thus will not be caught in the block above. Instead you have to put together a block like this:begin # Do some things rescue => ex puts "Error: #{ex}" rescue Timeout::Error => e puts "Timeout Error: #{e}" end </pre>
That will catch the Timeout error and allow you to deal with it appropriately.