javascript

1. Error 对象      EvalError    RangeError   TypeError   ReferenceError  

try{
    notExists();
}
catch(e){
    alert(e.name+':'+e.message);
}
try{
    var num =4
    if(num!=0)
        throw new Error('why me?');
}catch(e){
alert('in catch:'+e.name+':'+e.message);
}finally{
alert('in finally');

}
function myError(msg){
    this.name = 'God is '
    this.message = msg||'default self-defined error message';
}
myError.prototype = Object.create(Error.prototype);
myError.prototype.constructor = myError;
try {
    throw new myError();
}
catch(e){
    console.log(e.name +':'+e.message);
}

 

你可能感兴趣的:(javascript)