Hello all, quite new to ruby here.
I am trying to figure out how to catch exceptions and I am not having
Basically I have a script that loops over an array of ports and tries to
connect to see if there is a service running. If there is nothing
then I get a “Connection refused” error (ECONNREFUSED). In this case I
want to print a small message and move on to the next port, however, my
attempt at this just terminates the loop entirely. Here’s some
begin telnetPorts.each do |port|
puts "Port " + port.to_s + “:”
t = TCPSocket.new(host,port)
banner = t.gets
puts "Unable to connect to port: " + $!
As it stands, this does catch the exception just fine, but moves to the
block of code immediately. I tried using ‘next’ but it is giving me an
“unexpected next”. So how does one simply move on to the next port in
case? Do I need to rewrite it as a function?
Thanks for consideration,