[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

TCPSocket and rescue

Mark Probert

9/4/2003 9:39:00 PM

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?

--
-mark.

2 Answers

ts

9/5/2003 8:26:00 AM

0

>>>>> "M" == Mark Probert <probertm@NOSPAM_acm.org> writes:

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




Mark Probert

9/5/2003 2:11:00 PM

0

Guy did say ...

>
> you catch only StandardError, write it
>
> rescue Exception => e
>
Thank you, Guy.


-mark.