see_reply_address at something.invalid
Tue Aug 20 05:47:03 CEST 2002
> There was a recent thread on python-dev that
> mentioned lazy instantiation of exceptions at the C level; does that
> apply to for loops? That is, with the following code, does an actual
> exception object get created?
> def f():
> yield 1
> raise StopIteration
> for i in f():
> print i
From reading the interpreter source, it seems that the
"raise" statement always instantiates the exception
immediately if it's not already an instance. So, in
interpreted code, there's no advantage to writing
"raise C, v" instead of "raise C(v)".
However, I don't see any reason why it couldn't defer
instantiation the same as is done when you raise an
exception in C code. The code which catches exceptions
has to make sure it's instantiated in any case, whether
it was raised in intepreted or C code.
Perhaps it was thought that the gain wouldn't be worth
it in interpreted code. Or maybe the deferral of
instantiation is a recent invention that hasn't made
its way into the interpreter yet.
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
More information about the Python-list