Why exceptions shouldn't be used for flow control [Re: YAS to the "Reading line-by-line" Problem]
Phil Mayes
nospam at bitbucket.com
Sun Jun 27 01:07:03 EDT 1999
William Tanksley wrote in message ...
>On Fri, 25 Jun 1999 10:19:05 +1200, Greg Ewing wrote:
>>William Tanksley wrote:
> [long discussion of f.eof() vs. exceptions excised]
>OTOH, that particular exceptionn would get thrown only in a truly bizzare
>situation, because all code would look somethinng like this:
>
>while not f.eof():
> line = f.readline()
> # ...
I have sometimes had to read non-atomic objects from a stream, eg:
while 1:
name = f.readline()
addr1 = f.readline()
addr2 = f.readline()
# combine name, addr1, addr2 into something
# put it somewhere
Other examples: Pascal-style strings; mixed-length objects.
Doing this properly in C is a pain because of the requirement to test
error/eof after reading each fragment. Assuming low overhead, exceptions
strike me as a significant improvement.
--
Phil Mayes pmayes AT olivebr DOT com
Olive Branch Software - home of Arranger
More information about the Python-list
mailing list