try.. except

Giganews Newsgroups
Subject: try.. except
Posted by:  bluewolf (bluewo…@yournamehere.com)
Date: Sun, 9 Nov 2003

I want to make a news program that scan's a list of news servers and gets
group counts on a list of groups then creates stats on the different news
servers with the groups.

My problem is I have a middle to low programmer knowlegde and don't know
how to use the try.. except.. functions and indy keeps raising an
exception when it can't connect to a server and when the timeout happens.
I would like some information on how to handle the exceptions, and in the
exception how to set a varible saying that the server is unreachable or
it was a connection timedout.

I have this, but don't know how to setup the class for the execption.

---code---
//global vars
type
  //?? would this be right
  eMyStatsConnectionError = EIdSocketErrror(class);
end;
var
  ConnectErr  : Boolean;
//global vars

procedure TForm1.Button1Click(Sender: TObject);
begin
    // 'm' left out to raise exception.
    IdNNTP1.Host:='news.atozedsoftware.co';
    IdNNTP1.Port := 119;
    Try
      IdNNTP1.Connect(1000);
      IdNNTP1.SelectGroup('atozedsoftware.indy.protocol.nntp');
      ListBox1.Items.Add('Message Count: '+IntToStr(idNNTP1.MsgCount));
      ListBox1.Items.Add('Message Hi: '+IntToStr(idNNTP1.MsgHigh));
      ListBox1.Items.Add('Message Low: '+IntToStr(idNNTP1.MsgLow));
      IdNNTP1.Disconnect;
    Except
      on e:EMyStatsConnectionError do connecterr := false;
    end;
end;

Replies