Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] PEP 348: Exception Reorganization for Python 3.0

Brett Cannonbcannon at gmail.com
Fri Aug 5 21:02:46 CEST 2005


On 8/5/05, Raymond Hettinger <raymond.hettinger at verizon.net> wrote:> The PEP moves StopIteration out from under Exception so that it cannot> be caught by a bare except or an explicit "except Exception".>> IMO, this is a mistake.  In either form, a programmer is stating that> they want to catch and handle just about anything.  There is a> reasonable argument that SystemExit special and should float to the top,> but that is not the case with StopIteration.>> When a user creates their own exception for exiting multiple levels of> loops or frames, should they inherit from ControlFlowException on the> theory that it no different in intent from StopIteration or should they> inherit from UserError on the theory that it is a custom exception?I say ControlFlowException.  UserError is meant for quick-and-dirtyexception usage and not as a base for user error exceptions.  If thename is confusing it can be changed to SimpleError.>  Do> you really want routine control-flow exceptions to bypass "except> Exception".Yes.>  I suspect that will lead to coding errors that are very> difficult to spot (it sure looks like it should catch a StopIteration).>I honestly don't think it will.  People who are going to care aboutcatching StopIteration are writing custom iterators, not something anewbie will porobably be doing and thus should know to be specificabout what exceptions they are catching when they have a specificthing in mind.> Be careful with these proposals.  While well intentioned, they have> ramifications that aren't instantly apparent.  Each one needs some deep> thought, user discussion, usability testing, and a darned good reason> for changing what we already have in the field.>Right, which is why this is all in a PEP, so the discussion can happenand the kinks can be worked out.  As for the testing, that can happenwith __future__ statements, people trying out a patch, or maybe evensome testing branch of Python for possible 3000 features.-Brett


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp