[Python-Dev] GeneratorExit inheriting from Exception

Giovanni Bajo rasky at develer.com
Sat Mar 18 20:13:50 CET 2006

Barry Warsaw wrote:

> >Unless this new proposal also includes changing the meaning of
>> "except:" to "except Error".

> It's worth debating.  OT1H, it's a semantic different for Python 2.x
> (although +1 on the idea for Py3K).

I was speaking of Py3K here, yes.

> Going along with that, maybe the interpreter should do something
> different when an Exception that's not an Error reaches the top
> (e.g. not print a traceback if KeyboardInterrupt is seen -- 
> we usually just catch that, print "Interrupted" and exit).

SystemExit is already special-cased, as far as I can tell. KeyboardInterrupt
could be in fact be special cased as well (I saw many Python newbies -- but
otherwise experienced -- being disgusted at first when they interrupt their
code with CTRL+C: they expect the program to exit "almost silently").

>> Also, under this new proposal, we could even remove
>> Exception from the builtins namespace in Py3k. It's almost
>> always wrong to use it, and if you really really need it, it's
>> spelled exceptions.Exception.

> I'm not sure I'd go as far as hiding Exception, since I don't think the
> penalty is that great and it makes it easier to document.

The situation (in Py3k) I was thinking is when people see this code:

    # something

and want to change it so to get a name to the exception object. I *think* many
could get confused and write:

except Exception, e:
    # something

which changes the meaning. It "sounds" correct, but it's wrong. Of course, it's
easy to argue that "Exception" is just that, and people actually meant "Error".
In a way, the current PEP352 is superior here because it makes harder to do the
"bad" thing by giving it a complex name (BaseException).

Giovanni Bajo

More information about the Python-Dev mailing list