throw vs throw new Error

时间:2017-02-05 15:04:47

标签: javascript

throw和throw new之间有什么区别错误,我有点困惑似乎只使用throw关键字创建了一个Error对象,那么为什么新的Error与throw一起使用? 示例

try{
   throw "something went wrong";//this works
}
catch(e){
 console.log(e);
 }


 try{
    throw new Error("something went wrong");//this also works but with    
                                             // longer syntax
 }
 catch(e){
      console.log(e);
 }

0 个答案:

没有答案