我可以在 JavaScript 中使用 try/catch 而不指定 catch 参数/标识符吗? [英] Can I use a try/catch in JavaScript without specifying the catch argument/identifier?
本文介绍了我可以在 JavaScript 中使用 try/catch 而不指定 catch 参数/标识符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有办法在执行 JS try/catch 时不指定参数.每次我尝试这个时,try/catch 都不起作用.
I was wondering if there is a way to not specify the argument when doing a JS try/catch. Every time I try this though, the try/catch doesn't work.
工作版本:
try{
//Breaking code
} catch(e){
//Nothing happens here
}
我的想法(没有e"):
What I have in mind (No 'e'):
try{
//Breaking code
} catch(){
//Nothing happens here
}
推荐答案
这是一个过时的答案.它不再适用于当前版本的 JavaScript.有关详细信息,请参阅其他答案.
你就是不能.规范说在catch之后括号内必须始终有一个标识符代码>.
You just can't. The spec says that there must always be an identifier inside parens after catch
.
这篇关于我可以在 JavaScript 中使用 try/catch 而不指定 catch 参数/标识符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文