How come StopIteration.__base__ is not BaseException?

random832 at fastmail.us random832 at fastmail.us
Mon Aug 26 16:10:15 EDT 2013


On Mon, Aug 26, 2013, at 15:37, Marco Buttu wrote:
> Since StopIteration is not an error, how come does it inherit directly 
> from Exception and not from BaseException?

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.



More information about the Python-list mailing list