[Python-ideas] sentinel_exception argument to `iter`

Chris Angelico rosuav at gmail.com
Fri Feb 7 07:59:50 CET 2014


On Fri, Feb 7, 2014 at 5:52 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
> I'm actually not sure whether it's legal to use, say, 0 or "" as the except expression. In recent 3.4 builds, it seems to be accepted, and to never catch anything. So, if that's guaranteed by the language, it's just a simple typo to fix and your simplified implementation works perfectly.
>

In 3.4b2:

>>> def f():
raise StopIteration

>>> try:
f()
except "":
print("Blank exception caught")

Traceback (most recent call last):
  File "<pyshell#693>", line 2, in <module>
    f()
  File "<pyshell#691>", line 2, in f
    raise StopIteration
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#693>", line 3, in <module>
    except "":
TypeError: catching classes that do not inherit from BaseException is
not allowed


It doesn't bomb until something gets raised. Is that changed in a
newer build? (This is the newest I have on here.)

ChrisA


More information about the Python-ideas mailing list