> -----Original Message-----
> From: akanksha [mailto:akanksha.baid / gmail.com] 
> Sent: Tuesday, August 08, 2006 12:45 PM
> To: ruby-talk ML
> Subject: mechanize timeout errors
> 
> 
> I am using mechanize for scraping some urls.
> begin
>      page = agent.get(url)
> rescue
>      puts "oops!!"
> end
> 
> catches invalid urls etc. , but how to I handle timeout 
> errors? In particular this is the error I get :
> 
> request-header: accept => */*
> request-header: user-agent => WWW-Mechanize/0.5.1
> (http://rubyforge.org/projects/mechanize/)
> /usr/local/lib/ruby/1.8/timeout.rb:54:in `rbuf_fill': 
> execution expired
> (Timeout::Error)
>         from /usr/local/lib/ruby/1.8/timeout.rb:56:in `timeout'
>         from /usr/local/lib/ruby/1.8/timeout.rb:76:in `timeout'

begin
   page = agent.get(url)
rescue Timeout::Error
   puts "Timeout!"
   raise
rescue
   puts "Some other error!"
   raise
end

If you want control over the timeout value I think you'll need to
re-wrap the call to agent.get in your own timeout block:

require 'timeout'

begin
   Timeout.timeout(5){ agent.get(url) }
...

If you're wondering why your rescue didn't handle the exception, it's
because Timeout::Error is a subclass of Interrupt, not StandardError.

Regards,

Dan


This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly 
prohibited and may be unlawful.  If you have received this communication 
in error, please immediately notify the sender by reply e-mail and destroy 
all copies of the communication and any attachments.