Generator issue: exceptions while initializing arguments

Brendan Eich brendan at
Mon Sep 10 11:08:02 PDT 2012

Brendan Eich wrote:
>>  Any exceptions that occur in the generator body prior to the first 
>> yield will be expected at the first call to next().
> That would be loc 2, though -- seems to go against what you wrote 
> earlier.

I stick by this! ;-)

> It also is not how generators work in Python or JS1.7+:

Sorry for rehashing something else here, I see your point. If we want 
loc 1 (if *you* do ;-), then there could be a pending exception from a 
thrower() default parameter. That's where I started, up-thread. But this 
is strictly more complicated.

Morever, the opening left brace does not make a scope boundary between 
formals and local vars. It doesn't even make a hoisting boundary for 

js> function f(x){ function x(){}; return x; }
js> f(42)
function x(){}

Sorry, C fans (sorry, me!).

> Python 2.6.6 (r266:84292, May 28 2011, 19:08:00)
> [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def g():
> ...   raise BaseException('foo')
> ...   yield
> ...
> >>> i = g()
> >>>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 2, in g
> BaseException: foo
> js> function g(){throw 42; yield}
> js> i = g()
> ({})
> js>
> uncaught exception: 42
> The exception comes after the first .next() that starts from the 
> implicit yield point.
> The design doesn't work if there's no implicit yield first. The rest 
> of what's shown above follows from that.

More information about the es-discuss mailing list