Generator return() and exceptions

Andy Wingo wingo at
Wed Jul 23 01:25:21 PDT 2014


The TC39 notes do not record any discussion of return() causing an
exception to be thrown.

I understand that one of the concerns was about guards and catch blocks,
but making return() throw an exception does not affect that in the

It's already the case that any catch block may see any old exception.
Adding a new kind of exception doesn't affect that; properly written
catch blocks have to test the positive presence of the exception they
are looking for, not the absence of exceptions they aren't interested
in.  Magical return() is no better here because, as you note, return can
be caught too.

There are valid cases in which you can have a catch without a guard;
these are when can enumerate the possible exceptions that a part of your
program will throw.  However this condition necessarily limits the size
of the try{} block -- it is unlikely to contain a yield.  So no problem
there either.

WDYT?  I really really really do not want magical returns.


More information about the es-discuss mailing list