views:

25

answers:

0

I'm using net-ssh to iterate over a couple of hosts in a loop. This bit of code will throw an error if the username entered is incorrect.

Net::SSH.start(host, user) do |ssh|                                                       
  out = ssh.exec!(exec)                                                                   
  puts out                                                                                
end

How can I catch that error, report it, and then keep moving with the other hosts in the loop? I'm using begin/rescue in other places in the script, but it feels kind of clunky. Is there a better way to handle errors in this instance?

Thanks!