function UserException(message){
this.name = "UserException"; //constructor
this.message = message || "";
/**
* constructor
* if (message is undefined) this.message = "";
* else this.message = message;
*/
this.getMessage = function(){
return this.message;
}
this.getName = function(){
return this.name;
}
this.toString = function(){
return this.name;
}
}
try{
throw new UserException("test user exception");
}catch(ex){
console.log(ex);
console.log(ex.toString());
console.log("excetion name : " + ex.getName());
console.log("exception message : " + ex.getMessage());
if(ex instanceof UserException){
console.log("exception type is UserException");
}
}
วันอังคารที่ 25 ธันวาคม พ.ศ. 2555
custom exception type javascript
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)

ไม่มีความคิดเห็น:
แสดงความคิดเห็น