From: darren kirby Date: 2006-06-03T05:41:44+09:00 Subject: Exceptions inside loops... --nextPart2048266.nJRMHZK6vV Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello all, quite new to ruby here. I am trying to figure out how to catch exceptions and I am not having luck.= =20 Basically I have a script that loops over an array of ports and tries to=20 connect to see if there is a service running. If there is nothing running=20 then I get a "Connection refused" error (ECONNREFUSED). In this case I just= =20 want to print a small message and move on to the next port, however, my=20 attempt at this just terminates the loop entirely. Here's some (simplified)= =20 code: begin telnetPorts.each do |port| puts "Port " + port.to_s + ":" t =3D TCPSocket.new(host,port) banner =3D t.gets t.close end rescue SystemCallError puts "Unable to connect to port: " + $! end As it stands, this does catch the exception just fine, but moves to the nex= t=20 block of code immediately. I tried using 'next' but it is giving me an erro= r:=20 "unexpected next". So how does one simply move on to the next port in this= =20 case? Do I need to rewrite it as a function? Thanks for consideration, =2Dd =2D-=20 darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." =2D Dennis Ritchie and Ken Thompson, June 1972 --nextPart2048266.nJRMHZK6vV Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQBEgKKFwPD5Cr/3CJgRAqhFAKCQLclc7JzYoeg8kwpko/43AhqwUwCffaH6 5nFLgZEZkVywJ2GmoacSy1c= =n4cx -----END PGP SIGNATURE----- --nextPart2048266.nJRMHZK6vV--