TCPSocket and rescue

Hi, rubyists.

I am trying to telnet to a large number of boxes. I have created a
wrapper around the net/telnet. One of the methods is called 'alive?'
that checks to see if the node can be reached prior to running up the
Telnet.

def alive?
begin
t = TCPSocket.new(@host,@port) # line= ./bsn.rb:83
t.close
return true
rescue => e
@exception = e
return false
end
end

When I run the this as part of a bigger program I get the following
exceptions raised all pointing to the TCPSocket.new call:

Exception Errno::ETIMEDOUT' at ./bsn.rb:83 - Connection timed out - connect(2) ExceptionErrno::ENETUNREACH’ at ./bsn.rb:83 - Network is unreachable -
connect(2)
Exception Errno::ENETUNREACH' at ./bsn.rb:83 - Network is unreachable - connect(2) ExceptionErrno::ETIMEDOUT’ at ./bsn.rb:83 - Connection timed out -
connect(2)

I am surprised that I am seeing these exceptions, given the open rescue
clause.

Any ideas?

···


-mark.

  def alive?
    begin
      t = TCPSocket.new(@host,@port) # line= ./bsn.rb:83
      t.close
      return true
    rescue => e

you catch only StandardError, write it

       rescue Exception => e

      @exception = e
      return false
    end
  end

Guy Decoux

Guy did say …

you catch only StandardError, write it

   rescue Exception => e

Thank you, Guy.

-mark.