and one short example.


def login
  begin
    # connect, login, ...
  rescue TimeoutError
    STDERR << "login failed; #$ERROR_INFO\n"
    STDERR << "retry...\n"
    retry
  rescue Errno::ECONNRESET # Connection reset by peer
    STDERR << "login failed; #$ERROR_INFO\n"
    STDERR << "retry...\n"
    retry
  rescue Errno::ECONNREFUSED # Connection refused
    STDERR << "login failed; #$ERROR_INFO\n"
    STDERR << "retry...\n"
    retry
  rescue
    STDERR << $ERROR_INFO.inspect << "\n"
    STDERR << "login failed.\n" << $ERROR_INFO.to_s << "\n" << $ERROR_POSITION.join("\n")
    exit
  end
end
 
def cmd(command)
  begin
    # some command
  rescue Errno::ECONNRESET # Connection reset by peer
    STDERR << "command failed; #$ERROR_INFO\n"
    exit
  rescue
    STDERR << "try logout.\n"
    logout
  end
end

def logout
  begin
    # logout, ...
  rescue Errno::ECONNRESET # Connection reset by peer
    exit
  rescue TimeoutError
    STDERR << "logout failed; #$ERROR_INFO\n"
    exit
  rescue
    STDERR << "logout failed.\n" << $ERROR_INFO.to_s << "\n" << $ERROR_POSITION.join("\n")
    exit
  end
end


-- 
Wakou Aoyama  <wakou / fsinet.or.jp>