block lambda revival, now with semantics

Brendan Eich brendan at mozilla.com
Sat Jun 4 20:43:26 PDT 2011


On Jun 4, 2011, at 7:55 PM, Peter Michaux wrote:

> Would we be able to do the following to ensure the file is closed if
> "fn" is either a function that throws or is a lambda that returns?
> 
>    var withFile = function(filename, fn) {
>        var file = openFile(filename);
>        try {
>            fn(file);
>        }
>        finally {
>            file.close();
>        }
>    };

Yes, finally clauses run on the way out due to return. The return from a lambda is like an exception, but not reified as such and not catchable. But finallys run.

/be


More information about the es-discuss mailing list