On Feb 13, 4:17 am, Christophe Grand <[EMAIL PROTECTED]> wrote:
> Hello,
>
> try..catch seems not to catch an exception if it is thrown from a return
> statement:
>
> js> nofail = function(f) {
>         return function() {
>                 try {
>                         return f.apply(this, arguments);
>                 } catch (e) {
>                         return;
>                 }
>         }}
>
> js> f = nofail(function() {throw "argh"})
> js> f() === undefined
> js: "<stdin>", line 98: exception from uncaught JavaScript throw: argh
>         at <stdin>:98
>         at <stdin>:99
>
> But if I introduce a variable so as to throw the exception from a
> regular statement:
>
> js> nofail = function(f) {
>         return function() {
>                 try {
>                         var r = f.apply(this, arguments);
>                         return r;
>                 } catch (e) {
>                         return;
>                 }
>         }}
>
> js> f = nofail(function() {throw "argh"})
> js> f() === undefined
> true
>
> It works!
>
> Christophe

Good catch. This was indeed a Rhino bug.

The problem was that our interpreted mode tail call optimization was
interfering with catching the exception. Compiled mode was not
affected. I've checked in a fix, which is simply to disable tail call
elimination when in the scope of a try block.

--Norris
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to