M
Mark Probert
Can someone please let me know what I am doing wrong here?
I can't seem to catch the exception ..
$ cat test.rb
require 'socket'
def alive(host, port=80)
s = "host=#{host} : "
t = TCPSocket.new(host, port)
begin
s << " made it!"
rescue Errno::ETIMEDOUT
s << " Timed out -- node unreachable"
rescue Exception => e
s << " exception = #{e}"
ensure
t.close
end
return s
end
puts alive('10.10.10.2')
$ ruby test.rb
test.rb:6:in `initialize': Operation timed out - connect(2) (Errno::ETIMEDOUT)
from test.rb:6:in `new'
from test.rb:6:in `alive'
from test.rb:19
Regards,
-mark. (probertm at acm dot org)
I can't seem to catch the exception ..
$ cat test.rb
require 'socket'
def alive(host, port=80)
s = "host=#{host} : "
t = TCPSocket.new(host, port)
begin
s << " made it!"
rescue Errno::ETIMEDOUT
s << " Timed out -- node unreachable"
rescue Exception => e
s << " exception = #{e}"
ensure
t.close
end
return s
end
puts alive('10.10.10.2')
$ ruby test.rb
test.rb:6:in `initialize': Operation timed out - connect(2) (Errno::ETIMEDOUT)
from test.rb:6:in `new'
from test.rb:6:in `alive'
from test.rb:19
Regards,
-mark. (probertm at acm dot org)