From: Rodrigo Bermejo Date: 2009-09-10T22:49:17+09:00 Subject: Re: Net::Telnet login() intercept authentication error born in USSR wrote: > CODE: >>user_login='user1' >>user_paswd='xxxxxx' >>... >>tserv = Net::Telnet::new("Host" => "192.168.1.5", >>"Timeout" => 1, "Prompt" => /[$%#>] \z/n) >> >> begin >> ans=tserv.login(user_login,user_paswd) >> rescue => err >> puts err >> end >> >>puts ans >>... > > if user_login or user_paswd is wrong the application is hanging (don't > know how it is on english, i mean that application stops). How can i > intercept error. > > http://www.ruby-doc.org tells that 'The method returns all data received > during the login process from the host, including the echoed username > but not the password (which the host should not echo). If a block is > passed in, this received data is also yielded to the block as it is > received. ', but nothing about wrong authentication. Not all exceptions are created the same way If the exception is a parent of StandardError, you will catch it with a simple rescue , for other kind of exception this does not apply begin tserv = Net::Telnet::new("Host" => "192.168.1.5", "Timeout" => 5, "Prompt" => /[$%#>] \z/n) ans=tserv.login(user_login,user_paswd) rescue TimeoutError => e ans="Error while connecting: #{e}" end puts ans -ronnie -- Posted via http://www.ruby-forum.com/.