【发布时间】:2011-05-31 18:23:20
【问题描述】:
// Create an object type UserException
function UserException (message){
this.message=message;
this.name="UserException";
}
// Make the exception convert to a pretty string when used as
// a string (e.g. by the error console)
UserException.prototype.toString = function (){
return this.name + ': "' + this.message + '"';
}
// Create an instance of the object type and throw it
throw new UserException("Value too high");
这将如何使用?
【问题讨论】:
-
你熟悉抛出异常吗?我正在尝试确定在什么级别上解释这一点。
-
等等,UserException.prototype在这里做了什么?
标签: javascript try-catch