Hi ..

Bill Atkins <batkins57 / gmail.com> wrote:
>
> Add a rescue clause for the exception you're getting: ...
> Is that what you're looking for?
> 

Not quite.

I guess the real qustion is why Timeout::Error doesn't trap 
Errno::ETIMEDOUT.  The socket times out before the timeout() and raises a 
different timeout error.  Perhaps it would be better if, when a block is 
wrapped in a Timeout::timeout, that all subservient timeouts should be 
caught by the  single rescue.

It does raise the question why the generic rescue isn't triggered.


> Bill Atkins
> 
> On Tue, 5 Oct 2004 06:09:53 +0900, Mark Probert
> <probertm / nospam-acm.org> wrote: 
>> 
>> Hi ..
>> 
>> I have the following code:
>> 
>>   def alive?(host,port)
>>     ok = false
>>     begin
>>         Timeout::timeout(30) {  
>>             begin
>>                 t = TCPSocket.new(host,port) # <--- line 150
>>                 t.close
>>                 ok = true
>>             rescue Exception => e  # why not caught here?
>>                 @exception = e
>>             end
>>         }
>>      rescue Timeout::Error => e  # or here?
>>          @exception = e
>>      end
>>      return ok
>>   end
>> 
>> In a known failure case, TCPSocket will fail (no host connectivity).
>> 
>> However,
>> 
>> 13:56 (hobbes)$ ruby foo.rb
>> Exception `Errno::ETIMEDOUT' at ./bsn.rb:150 - Connection timed out -
>> 
>> 13:57 (hobbes)$ ruby -v
>> ruby 1.8.1 (2003-12-25) [i386-cygwin]
>> 
>> What is the right way of handling this exception?
>> 
>> --
>> -mark.  (probertm @ acm dot org)
>> 
>>
> 
> 
> 



-- 
-mark.  (probertm @ acm dot org)