14.异常捕获

2018-01-27  本文已影响0人  Ching_Lee

1.try catch

 function demo(){
    try{
     alert(str);
    }catch (err){
      alert(err);
   }
   demo();
}

2.throw

自定义错误

function demo(){
   try{
       let e=document.getElementById("txt").value;
       if(e==""){
       throw "请输入";
       }
    }catch(err){
        alert(err);
    }
}
上一篇 下一篇

猜你喜欢

热点阅读