How come StopIteration.__base__ is not BaseException?

Marco Buttu marco.buttu at gmail.com
Tue Aug 27 02:17:15 EDT 2013


On 08/26/2013 10:10 PM, random832 at fastmail.us wrote:

> The reason KeyboardInterrupt and SystemExit inherit from BaseException
> is because you often want them to escape (allowing the program to quit)
> from code that would otherwise catch them (by catching Exception). On
> the contrary, StopIteration is almost always used in a context that
> catches it specifically.

But if I want to catch it specifically (except BaseIteration), why
doesn't it hinerit directly from BaseException? It's not an error and 
it's not a warning. I would like to see a piece of code in which it is
useful to catch it generically with a except Exception clause instead of 
an except StopIteration...
Regards
-- 
Marco



More information about the Python-list mailing list