When should you use try/catch in JavaScript?

后端 未结 7 993
旧时难觅i
旧时难觅i 2021-01-30 00:53

When I\'m developing normal web application with JavaScript, the try/catch statement is not needed usually. There\'s no checked exception, File IO or database conne

7条回答
  •  青春惊慌失措
    2021-01-30 01:49

    External Javascript libraries and widgets often make use of exceptions for instantiation errors. It's common to need to:

    try {
      var w = new Widget();
    }
    catch (e) {
      // widget failed
    }
    

提交回复
热议问题