[英]throw syntax in Javascript
How is 怎么
throw
{
name: 'type error',
message: 'provide numeric value'
};
a incorrect syntax when 错误语法
throw{
name: 'type error',
message: 'provide numeric value'
};
Is a correct syntax? 语法正确吗?
Is it really necessary to attach curly bracket with throw and why? 真的有必要在大括号上加上抛出吗?为什么?
For some reason, a semicolon is always inserted after a lone throw
keyword even though you can't legally have a throw
statement by itself, so what you get is this: 由于某种原因,即使您本身不能合法地拥有
throw
语句,也总是在一个单独的throw
关键字后插入一个分号,因此您将获得以下结果:
throw;
{
name: 'type error',
message: 'provide numeric value'
};
which results in a syntax error. 导致语法错误。
For what it's worth, C# (which, like JS, is also based on an ECMA standard) does support throw;
就其价值而言,C#(与JS类似,也基于ECMA标准)确实支持
throw;
statements as a way to rethrow an exception . 语句作为重新抛出异常的一种方式。 Perhaps they're futureproofing ECMAScript for support for a similar feature down the road.
也许他们正在对ECMAScript进行过时的验证,以支持将来的类似功能。 But this is just conjecture on my part.
但这只是我的推测。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.