TCPSocket and rescue

M

Mark Probert

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)
Exception `Errno::ENETUNREACH' at ./bsn.rb:83 - Network is unreachable -
connect(2)
Exception `Errno::ENETUNREACH' at ./bsn.rb:83 - Network is unreachable -
connect(2)
Exception `Errno::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?
 
T

ts

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

you catch only StandardError, write it

rescue Exception => e

M> @exception = e
M> return false
M> end
M> end


Guy Decoux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top