From: Eric Hodel Date: 2005-12-13T13:00:50+09:00 Subject: Re: How to catch Timeout::ERROR ? On Dec 12, 2005, at 6:00 PM, Verestiuc Vlad wrote: > Is there any way to catch Timeout::ERROR exception throw by timeout > () ? Timeout::Error > ====[cut here]====== > #!/usr/bin/env ruby > > > require 'open-uri' > require 'timeout' > > > begin > open("http://6.6.6.6/"){} > rescue => e rescue Timeout::Error => e > puts e.message > puts "I'm still running" > end Beware! You should use a subclass of Timeout::Error when nesting timeouts (Net::HTTP has timeouts inside) so that you don't trap the wrong timeout in the wrong place and run forever: irb(main):002:0> open('http://localhost:8080/') /usr/local/lib/ruby/1.8/timeout.rb:43:in `rbuf_fill': execution expired (Timeout::Error) -- Eric Hodel - drbrain@segment7.net - http://segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com