[Python-Dev] PEP 348 and ControlFlow

Eric Nieuwland eric.nieuwland at xs4all.nl
Tue Aug 9 22:32:50 CEST 2005


Dear all,

Sorry to bring this up again, but I think there is an inconsistency in 
PEP 348 in its current formulation.

 From PEP: "In Python 2.4, a bare except clause will catch any and all 
exceptions. Typically, though, this is not what is truly desired. More 
often than not one wants to catch all error exceptions that do not 
signify a "bad" interpreter state. In the new exception hierarchy this 
is condition is embodied by Exception. Thus bare except clauses will 
catch only exceptions inheriting from Exception."

So,  bare except will catch anything that is an Exception. This 
includes GeneratorExit and StopIteration, which contradicts: "It has 
been suggested that ControlFlowException should inherit from Exception. 
This idea has been rejected based on the thinking that control flow 
exceptions typically should not be caught by bare except clauses, 
whereas Exception subclasses should be."

To me this means GeneratorExit and StopIteration are to be taken out of 
the Exception subtree. It seems to me rather awkward to put them at the 
same level as Exception and TerminatingException. So there comes the 
old (yeah, I know REJECTED) idea of a ControlFlowException class, right 
next to Exception and TerminatingException:

BaseException
	+TerminatingException
		+ ...
	+ Exception
		+ ...
	+ ControlFlowException
		+ GeneratorExit
		+ StopIteration

Is my logic flawed (again ;-)?

--eric
Eric Nieuwland



More information about the Python-Dev mailing list