[Python-Dev] Problems with GeneratorExit deriving from Exception
Georg Brandl
g.brandl at gmx.net
Sun Dec 2 19:43:01 CET 2007
Antoine Pitrou schrieb:
> Hi,
>
> (I was asked to forward this from the bug tracker)
>
>> We have also run into problems where a task tries to "return" (yield Return())
>> from within a try: except Exception: block. Since returning from a coroutine is
>> roughly equivalent to "raise GeneratorExit", the exception can be caught and
>> ignored, with the same consequences as above.
>
> I may be missing something but why don't you just catch StandardError
> instead? If I believe Python 2.5's exception hierarchy it would catch
> anything under Exception except for GeneratorExit, StopIteration and the
> various Warnings.
Problem is, many (most?) third-party modules derive their exceptions from
Exception, not StandardError, so you'd have to add special cases for them
too.
Georg
--
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.
More information about the Python-Dev
mailing list