Error Handling for SSH Connection
I'm trying to figure out how to handle exceptions brought up by starting an SSH connection that fails.
For example, I have this code
This is stripped down version of it, but basically, it tries to SSH to a Linux box given the connection information from the array in the beginning, and if it cannot connect successfully (therefore raising the SocketError exception, for example), I want it to exit out of the current block of code (the EACH block), so the next iteration of $arrConnInfo is read in and processed.
$arrConnInfo.each do |strConnInfo|
strConnInfo = strConnInfo.split(",")
# Load connection variables
strHostName = strConnInfo
strUserName = strConnInfo
strUserPwd = strConnInfo
Net::SSH.start( strHostName, strUserName, strUserPwd ) do |session|
shell = session.shell.sync
$a = LinuxSystem.new(shell)
puts "Host name cannot be resolved."
#work with SSH connection here if connection is successful....
Right now, if the SocketError exception is brought up, it hits break and the program stops. How can I code it so it will simply move on to the next iteration? I don't find much information on the break method, so are there any alternatives?