Multiple catch in javascript

后端 未结 4 984
清歌不尽
清歌不尽 2021-01-04 00:34

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; 
}
ca         


        
4条回答
  •  温柔的废话
    2021-01-04 01:25

    Try in a that way:

    try {
      throw 1; 
    }
    catch(e) {
        if (e instanceof ReferenceError) {
           // ReferenceError action here
        } else if (typeof e === "string") {
           // error as a string action here
        } else {
           // General error here
        }
    }
    finally {}
    

提交回复
热议问题