Javascript中的多重捕获 [英] Multiple catch in javascript

查看:40
本文介绍了Javascript中的多重捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在J S(ES5或ES6)中使用多个catch,如下所述(仅为示例):

Is it possible to use multiple catch in JS(ES5 or ES6) like I describe below (it is only example):

try {
­­­­  // just an error
  throw 1; 
}
catch(e if e instanceof ReferenceError) {
­­­­  // here i would like to manage errors which is 'undefined' type
}
catch(e if typeof e === "string") {
  ­­­­// here i can manage all string exeptions
}
// and so on and so on
catch(e) {
  ­­­­// and finally here i can manage another exeptions
}
finally {
­­­­  // and a simple finally block
}

这与 C# Java 中的相同.

提前谢谢!

推荐答案

否.在JavaScript或EcmaScript中不存在.

No. That does not exist in JavaScript or EcmaScript.

您可以使用 catch 内的 if [... else if] ... else 完成相同的操作.

You can accomplish the same thing with an if[...else if]...else inside of the catch.

有些非标准实现(并且不在任何标准轨道上),

There are some non-standard implementations (and are not on any standard track) that do have it according to MDN.

这篇关于Javascript中的多重捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆