[Python-Dev] Re: Dangerous exceptions (was Re: Another test_compiler mystery) (original) (raw)

David Eppstein eppstein at ics.uci.edu
Tue Sep 7 17:31:41 CEST 2004


In article <ca471dc2040906184648d95e55 at mail.gmail.com>, Guido van Rossum <gvanrossum at gmail.com> wrote:

> It's not really the same subject, but the exception that gives me the > most grief is StopIteration. I have to keep remembering to never call > .next() without catching it; if I forget, I get bugs where some loop > several levels back in the call tree mysteriously exits.

Are you sure? This sounds like superstition to me, since that's not how loops work. Raising StopIteration in the middle of a loop does not break out of the loop -- only raising StopIteration from a next() breaks a loop. Or are you talking about nested next() calls? That's the only case where the behavior you are citing occurs.

I don't remember, it could have been nested next()s.

-- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/



More information about the Python-Dev mailing list