[Python-Dev] GeneratorExit inheriting from Exception

Michael Chermside mcherm at mcherm.com
Mon Mar 20 20:43:28 CET 2006


Barry writes:
> I still believe in this, and I'm thankful for the support I've seen.  It
> won't happen for Python 2.x, but I do plan on addressing this for Py3K.

When you do, I'd like you to consider one change to the names. You are
proposing this:

> Exception
> +- KeyboardInterrupt
> +- GeneratorExit
> +- SystemExit
> +- StopIteration
> +- Error
> |  +- ImportError
> |  +- (etc.)
    [...]

If we use that structure, I still strongly feel that what you call "Error"
ought to be named "Exception" (and what you call "Exception" should be
named "BaseException" or perhaps "Raisable"). The reason is this:

Most people coming to Python today are coming from languages more modern
than Fortran and C, and (if they have any programming background at all)
they are familiar with the idea of an exception. When chatting around the
water cooler, they probably call it "an exception", rather than "a dingus",
"one of those thingys that unwinds the stack until reaching a handler",
or even "an error". (The term "an error" is usually used around the
water cooler for any kind of mistake, whether human or programatic.) This
is encouraged in Python by the fact that the keyword for handling
exceptions in Python is "except".

But we don't want people using the dingus at the top of the hierarchy --
only a few experts who know what they're doing should care about that
one. We want them using the one that you call "Error". So by naming
that one "Exception", we take advantage of the meaning of the word, the
experience from other languages, and the keywords of the language to
encourage correct usage. Naming the top level dingus something slightly
odd is a small price to pay (although both "BaseException" and "Raisable"
seem instantly comprehensible to me).

I present Java as an example. Given it's position as the new Cobol, there
are literally hundreds of thousands of not-very-skillful Java programmers
out there. Yet it is rare to see them write "catch Throwable" when they
should use "catch Exception". That mistake is far more common among
beginning Python users. Surely we can do at least as well as Java!

-- Michael Chermside

PS: I've intentionally ignored the question Guido raised about whether
Warning belongs under your "Error" or your "Exception".



More information about the Python-Dev mailing list