Why does indy use exceptions for control flow.

Giganews Newsgroups
Subject: Why does indy use exceptions for control flow.
Posted by:  Karl (no_email.no_place.home)
Date: Sat, 13 Sep 2003

Hi all,

I am curious why the Indy components use exceptions for program control

What I mean here is that I often see exceptions raised (exposed by the BCB
6 debugger and reaching user code) for expected situations. From a software
engineering point of view, exceptions sould only be used for "excpetions".
If I use the FTP component to get a directory listing like such:

  FTP->List(files, "fileThatDoesNotExist", True);
  I get a EIdProtocolReplyError if the file does not exist. To me this is
not an exception, this is an expected result for which I'd expect a list of
0 items returned.. I understand that I can just check the ReplyErrorCode to
see what occured, but this means I must use exception handling for expected
program flow = poor design.. Why would I do this for a file which does not
exist you ask? To check if the file exists!

Exceptions are intended to seperate program code from error handling, this
just mixes the two and almost defeats the intended purpose of exceptions.

Why would an exception be thrown? What is the purpose of this?

I have also noticed the the List method also raises EIdConnClosedGracefully
which is handled before reaching user code, but which is exposed by the BCB
debugger. This has confused a few people as you can see from reading this

Thanks for developing this great set of components.