This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: yield in except clause causes exception context to be lost
Type: behavior Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Adam.Bielański, benjamin.peterson, georg.brandl, ronniemaor
Priority: normal Keywords:

Created on 2009-12-22 19:48 by ronniemaor, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg96812 - (view) Author: Ronnie Maor (ronniemaor) Date: 2009-12-22 19:48
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def coroutine():
...     try:
...             raise Exception('bla')
...     except:
...             yield 'foo'
...             raise
...
>>> for _ in coroutine():
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 6, in coroutine
TypeError: exceptions must be classes or instances, not NoneType

Seems that yielding in the except clause makes python forget the current 
exception, so a bar "raise" statement raises None, instead of the 
original exception.
changing except to except Exception,e: and raise to raise e throws the 
original exception, but then the original stack trace is lost.
msg96818 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-12-22 23:07
This is fixed in Python 3. I don't know if it's worth backporting the
changes because it may be hard to avoid also backporting the
incompatibilities in the exception model.
msg112456 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-02 12:41
This won't get backported now that 2.7 is in maintenance.
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51812
2013-01-18 10:44:08Adam.Bielańskisetnosy: + Adam.Bielański
2010-08-02 12:41:11georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112456

resolution: out of date
2009-12-22 23:07:09benjamin.petersonsetpriority: normal
nosy: + benjamin.peterson
messages: + msg96818

2009-12-22 19:48:37ronniemaorcreate