I just wonder - why we have to use exceptions and exception handling so
often? I mean, why exceptions, not function results?

Because exceptions can be handled an the desired level while function results must be handled at each level et propagated to the next one. Structured exception handling is the way to go with OOP.

Personally... I hate exceptions...

That was my opinion in the beginning. I quickly reversed my opinion when I understood how to benefit from the idea of structured exception handling.
--
[EMAIL PROTECTED]
http://www.overbyte.be


----- Original Message ----- From: "Piotr Hellrayzer Dałek" <[EMAIL PROTECTED]>
To: "TWSocket" <twsocket@elists.org>
Sent: Friday, July 01, 2005 12:03 AM
Subject: [twsocket] Why exceptions?


Hi!

I just wonder - why we have to use exceptions and exception handling so
often? I mean, why exceptions, not function results? For example:

procedure TNntpCli.List(DestStream : TStream);
begin
   if FState <> nntpReady then
  raise NntpException.Create('Not ready for LIST');
   FDataStream      := DestStream;

   FRequestType     := nntpList;
   FRequest         := 'LIST NEWSGROUPS';
   FNext            := GetArticleNext;
   StateChange(nntpWaitingResponse);
   SendRequest;
end;

Why not change it to

function TNntpCli.List(DestStream : TStream): boolean
begin
   if FState <> nntpReady then
  result:=false
   else
         begin;
         FDataStream      := DestStream;

         FRequestType     := nntpList;
         FRequest         := 'LIST NEWSGROUPS';
         FNext            := GetArticleNext;
         StateChange(nntpWaitingResponse);
         SendRequest;
         result:=true;
         end
end;

Currently, when exception is raised, sometimes I don't know if the exception
was raised in TWSocket, or TNntpCli (and I know that I could find that
out by checking exception class, but sometimes exception is raised not
because broken program logic, but because - for example - broken connection)
and I'm forced to use procedure-global exception handlers, or else I'll
end with a hell-lot of small exception handlers that would give me a bit
more info about what went wrong, but also complicate, enlarge and slow down RequestDone procedures (which have to handle >10000 - yes, over ten thousand
- RequestDones per connection).

Personally... I hate exceptions...

--
Piotr "Hellrayzer" Dalek
Author of ICS-Based Hellcore Mailer - an Outlook Express killer
http://www.hcm.prv.pl
[EMAIL PROTECTED]

----------------------------------------------------------------------
Startuj z INTERIA.PL! >>> http://link.interia.pl/f186c


--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to