R
Ry Nohryb
try {} catch (e) {} finally { return }
--> SyntaxError: Invalid return statement.
How come ?
--> SyntaxError: Invalid return statement.
How come ?
try {} catch (e) {} finally { return }
--> SyntaxError: Invalid return statement.
How come ?
Arrghhh:
(function () {
try {} catch (e) {} finally { return }})()
--> undefined
Sorry.
Ry Nohryb said:try {} catch (e) {} finally { return }
--> SyntaxError: Invalid return statement.
How come ?
The finally block "always" executes. Here's something a little more
interesting:
var a = (function () {
try { return "foo" } catch (e) {} finally { return "bar" }
})();
a // "bar"
Yep. Thanks. Very interesting indeed! What has happened to the first
return "foo" ?
The finally block "always" executes.[...]
Yep. Thanks. Very interesting indeed! What has happened to the first
return "foo" ?
On Aug 19, 7:49 pm, "Michael Haufe (\"TNO\")"
The finally block "always" executes.[...]
Per spec, yes. Now test that premise in any version of internet explorer
and you'll find it doesn't quite work.
What I believe the reasoning to be is that because a function
can only return once,
the return statement of the finally block takes
precedence since it is "guaranteed" to always execute.
Garrett Smith said:Keep in mind that SyntaxError can occur at runtime and that is just
what happens in V8 and SFX.
Older versions of Webkit interpret the return statement by exiting
global execution context, thus, anything after the finally won't be
evaluated. That is an ECMAScript conformance violation.
javascript:var e;try{return 1;}catch(ex){e=ex;}finally{alert("err:"+e);}
No. The return is syntactically correct and is properly executed.
This is a syntax error because the return is not inside a function body.
The original example was inside a function, and the return in the try
block is not a syntax error in any browser.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.