[Python-Dev] GeneratorExit inheriting from Exception

Giovanni Bajo rasky at develer.com
Sat Mar 18 19:32:36 CET 2006


Georg Brandl <g.brandl at gmx.net> wrote:

>> Exception
>> +- KeyboardInterrupt
>> +- GeneratorExit
>> +- SystemExit
>> +- StopIteration
>> +- Error
>>>  +- ImportError
>>>  +- (etc.)
>>>
>> +- Warning
>>    +- UserWarning
>>    +- (etc.)
>
> Cool! That's so far the clearest solution. An additional bonus is that
> except
> statements look nicer:
>
> except:            # still catches all Exceptions, just like
> except Exception:
>
> except Error:      # is what you normally should do

+1 on the general idea, I just don't specifically like that "except:" is the
"wrong" thing to do: part of the PEP352 idea was that people writing
"except:" out of ignorance would still not cause their program to intercept
KeyboardInterrupt, or StopIteration.

Unless this new proposal also includes changing the meaning of "except:" to
"except Error". 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.
-- 
Giovanni Bajo



More information about the Python-Dev mailing list