浏览器异常信息捕获

正常js 代码执行过程中遇到错误 将停止执行下去

 console.log(num);   //未定义 报错

console.log("错误不在输出") // 不再执行

===================================================

try(

console.log(num);  //未定义出错

)catch(e){

}

 

console.log("错误不在输出");   //正常执行

 

=====================================================

 

类数组转换数组兼容问题

this//类数组

var arr = [ ];

try{

 arr=Array.prototype.slice.call(this);

}

catch(e){

      for(var i= 0;i<this.length;i++){

       arr[arr.length] = this[i];

}

return arr;

 

 

 

======================

try{

//执行

}catch(e){

//try内报错再执行

//throw  new Error(" ");// 手动抛出异常后面代码不会执行   

//new ReferenceError    引用错误

//new  TypeError 类型错误

//new  RangeError  范围错误

}finally{

//不管报错都会执行  一般不用

}

 

e.message 显示报错信息

 

posted on 2017-12-22 23:09  cm笔记簿  阅读(287)  评论(0编辑  收藏  举报

导航