Hi,
   I was trying out the following snippet of code and just wanted to
know why the rescue doesn't work when the username or password are not
valid. The code works fine when both are valid, but I wanted to catch
invalid login error and take action, but so far can't do so.

As a beginner in Ruby could you show me a way out ...

require 'net/telnet'

uname = "prasad"
pwd = "prasad123"

begin
    tn = Net::Telnet.new({"Host"  =>  "localhost"})     { |str| print
str }

    tn.login(uname,pwd)  { |str| print str }

rescue
    print "The username or password is incorrect. \nPlease try again
...\n\n"

    print "\nEnter user name : "
    uname = STDIN

    print "\nEnter password : "
    pwd = STDIN

    retry

ensure
   tn.cmd("date")  { |str| print str }
   tn.close()

end
-- 
Posted via http://www.ruby-forum.com/.