'rbuf_fill': execution expired (Timeout::Error)
December 10th, 2007
This is a fun little exception in Ruby that you have to catch explicitly in order to get hold of it in a rescue block.
Say you had the following:
1 2 3 4 5 6 7 |
require 'net/pop3' begin Net::POP3.auth_only(@server, @port, @username, @password) rescue => e write_error_to_logfile(e) do_something_sensible end |
And the mail server could not be reached due to transient network problems -> that is, you are getting a socket timeout error.
Well, your code in the rescue block won’t get executed! Even though the script raises an Error!
Why is this?
Simple answer, because Timeout::Error is not a subclass of StandardError, it is a subclass of the Interrupt class.
So, that means you have to catch it explicitly, like so:
1 2 3 4 5 6 7 8 9 10 |
require 'net/pop3' begin Net::POP3.auth_only(@server, @port, @username, @password) rescue => e write_error_to_logfile(e) do_something_sensible rescue Timeout::Error => e write_error_to_logfile(e) do_something_sensible_for_timeout end |
And all will be good again, error caught!
blogLater
Mikel
December 18th, 2007 at 05:10 PM
Thank you very much ;)
January 11th, 2008 at 11:14 PM
Thanks, I had this same error and this cleared up my incorrect expectation that everything derived from a root Exception class.
January 30th, 2008 at 04:57 AM
http://blog.nicksieger.com/articles/2006/09/06/rubys-exception-hierarchy
Every exception derives from Exception, so you can do
begin # Thing that throws Timeouts, anything… rescue Exception => e puts ”#{e}\n#{e.backtrace.join(”\n”)}” end
February 21st, 2008 at 08:14 AM
this was a huge help!
March 1st, 2008 at 08:43 PM
This was e great help to me too… Thanks a lot!
March 15th, 2008 at 02:01 AM
Thanks, this error was really driving me crazy.
June 13th, 2008 at 11:23 PM
Thanks !
August 27th, 2008 at 02:20 AM
that was very helpful, thanks!
September 11th, 2008 at 08:54 PM
Thanks. this saved my debugging time.
September 26th, 2008 at 10:54 AM
Thx!!!
November 8th, 2008 at 12:04 AM
thank you, this was very helpful