标签:prot gif 错误记录 load return trycatch == highlight get
function TestTryCatch(){ try { } catch (error) { //error 类型如下 Error EvalError RangeError ReferenceError //SyntaxError TypeError URIError if(error instanceof TypeError){ }else if( error instanceof ReferenceError){ }else{ } } finally{ } } //17.2.2 抛出错误 function process(values){ if(!(values instanceof Array)){ throw new Error(‘process():Argument must be an array‘); } values.sort(); for(var i=0,len=values.length;i<len;i++){ if(values[i] >100){ return values[i]; } } return -1; } //自定义错误 function CustomError(message) { this.name =‘CustomError‘; this.message = message; } CustomError.prototype =new Error(); //17.2.3 错误(error)事件 window.onerror =function(message,url,line){ alert(message); return false; } //throw new CustomError(‘CustomError‘); var image = new Image(); image.addEventListener(‘load‘,function(event){ alert(‘Image loaded‘); },false); image.addEventListener(‘error‘,function(event){ alert(‘Image not laoded‘); },false); image.src =‘smilex.gif‘; //17.2.4 处理错误的策略 //略 //17.2.5 常见的错误类型 function concat(str1,str2,str3){ var result =str1+str2; if( typeof str3 ==‘string‘){ result +=str3; } return result; } function getQueryString(url){ if( typeof url ==‘string‘){ var pos = url.indexOf(‘?‘); if(pos>-1){ return url.substring(pos+1); } } } function reverseSort(values){ if( typeof values.sort ==‘function‘){ values.sort(); values.reverse(); } } //17.2.6 区分致命错误和非致命错误 //17.2.7 把错误记录到服务器
标签:prot gif 错误记录 load return trycatch == highlight get
原文地址:https://www.cnblogs.com/ms_senda/p/11518035.html