A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-August/102611.html below:

[Python-Dev] Exception chaining and generator finalisation

[Python-Dev] Exception chaining and generator finalisation [Python-Dev] Exception chaining and generator finalisationGreg Ewing greg.ewing at canterbury.ac.nz
Sun Aug 1 09:45:31 CEST 2010
Antoine Pitrou wrote:

> It only happens if you call close() explicitly:

Well, that's only because the exception is being ignored and
you're not getting a traceback at all.

If you arrange to get a traceback, the same thing happens.

   import traceback as tb

   def g():
     try:
       try:
         yield 1
       finally:
         raise ValueError("Hovercraft contains eels")
     except Exception:
       tb.print_exc()

   gi = g()
   next(gi)
   del gi

-- 
Greg


> 
>>>>def g():
> 
> ...   try: yield 1
> ...   finally: 1/0
> ... 
> 
>>>>gi = g()
>>>>next(gi)
> 
> 1
> 
>>>>del gi
> 
> Exception ZeroDivisionError: ZeroDivisionError('division by zero',) in
> <generator object g at 0x7fe50351ddc0> ignored
> 
>>>>gi = g()
>>>>next(gi)
> 
> 1
> 
>>>>next(gi)
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 3, in g
> ZeroDivisionError: division by zero
> 
> 
> 
> Regards
> 
> Antoine.
> 
> 
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/greg.ewing%40canterbury.ac.nz

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4