[Python-checkins] CVS: python/nondist/peps pep-0255.txt,1.6,1.7
Tim Peters
tim_one@users.sourceforge.net
Wed, 20 Jun 2001 12:08:23 -0700
Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv31571/peps
Modified Files:
pep-0255.txt
Log Message:
Added brief section about exception propagation.
Index: pep-0255.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0255.txt,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** pep-0255.txt 2001/06/19 20:11:50 1.6
--- pep-0255.txt 2001/06/20 19:08:20 1.7
***************
*** 170,173 ****
--- 170,203 ----
+ Generators and Exception Propagation
+
+ If an unhandled exception-- including, but not limited to,
+ StopIteration --is raised by, or passes through, a generator function,
+ then the exception is passed on to the caller in the usual way, and
+ subsequent attempts to resume the generator function raise
+ StopIteration. In other words, an unhandled exception terminates a
+ generator's useful life.
+
+ Example (not idiomatic but to illustrate the point):
+
+ >>> def f():
+ ... return 1/0
+ >>> def g():
+ ... yield f() # the zero division exception propagates
+ ... yield 42 # and we'll never get here
+ >>> k = g()
+ >>> k.next()
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in ?
+ File "<stdin>", line 2, in g
+ File "<stdin>", line 2, in f
+ ZeroDivisionError: integer division or modulo by zero
+ >>> k.next() # and the generator function cannot be resumed
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in ?
+ StopIteration
+ >>>
+
+
Example