From: Eric Hodel Date: 2005-04-03T17:37:15+09:00 Subject: Re: Handling Timeout::Error from TCPSocket --Apple-Mail-8-1066192019 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On 02 Apr 2005, at 16:19, Pat Maddox wrote: > Alright, I'm understanding it more. > > If I use timeout, am I still able to catch the SocketErrors that might > occur? I'd like to be able to differentiate between a host > unreachable, connection refused, and a time out. Refused would happen > before the timeout(), but I'm not sure that the other two would even > get thrown. Does timeout() just kill whatever's going on at the time? $ ruby -r timeout -e 'p Timeout::Error.ancestors' [Timeout::Error, Interrupt, SignalException, Exception, Object, Kernel] Interrupt is not caught by rescue by default, but you can tell timeout what kind of exception to give you: $ ruby -r timeout -e 'timeout 2, SyntaxError do sleep 3 end' /usr/local/lib/ruby/1.8/timeout.rb:42: execution expired (SyntaxError) from -e:1:in `timeout' from /usr/local/lib/ruby/1.8/timeout.rb:55:in `timeout' from -e:1 The benefit of inheriting off of interrupt is that it will cut a path straight out of the timeout block, unless you're looking for it on purpose. (So beware of nesting timeouts without creating subclasses of Timeout::Error). -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --Apple-Mail-8-1066192019 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (Darwin) iEYEARECAAYFAkJPqwIACgkQMypVHHlsnwQh2QCgtawzSY2Vn6nyE4i+xGOh79f7 nRkAn10xkRK0WmYjwrLBk4nQ8HZz8ftU =X+yj -----END PGP SIGNATURE----- --Apple-Mail-8-1066192019--