How javascript try…catch statement works

前端 未结 5 825
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 04:22

I am trying to test in browsermob if certain input field work or not. I am attempting to use a try...catch statement which I have never used before. I know that the form is:

5条回答
  •  庸人自扰
    2020-12-18 04:37

    the stuff inside try {...} is what you want to execute. The stuff in catch() { ... } is what you want to execute if you get any javascript errors from anything executed in the try {...}

    catch {...} only executes if there is a javascript error in the try {...} block. You can find out what the error is by doing for example this:

    try {
     // do something 
    } catch (err) {
      alert(err);
    }
    

提交回复
热议问题