RangeError - JavaScript Error 对象
RangeError
RangeError对象标明一个错误,当一个值不在其所允许的范围或者集合中。
语法
new RangeError([message[, fileName[, lineNumber]]])
参数
message
可选,可读的错误描述fileName
可选,包含造成异常代码的文件名lineNumber
可选,造成异常的代码所在的行数描述
试图传递一个number参数给一个范围内不包含该number的函数时则会引发RangeError。当传递一个不合法的length值作为Number.toPrecision()
),会出现RangeError。.
属性
RangeError.prototype
允许在RangeError对象上附加属性。
方法
RangeError
全局对象没有自带方法,但它通过可以原型链继承一些方法。
RangeError
实例
属性
RangeError.prototype.constructor
Specifies the function that created an instance's prototype.RangeError.prototype.message
Error message. Although ECMA-262 specifies thatRangeError
should provide its ownmessage
property, in SpiderMonkey, it inheritsError.prototype.message
.RangeError.prototype.name
Error name. Inherited fromError
.RangeError.prototype.fileName
Path to file that raised this error. Inherited fromError
.RangeError.prototype.lineNumber
Line number in file that raised this error. Inherited fromError
.RangeError.prototype.columnNumber
Column number in line that raised this error. Inherited fromError
.RangeError.prototype.stack
Stack trace. Inherited fromError
.方法
Although theRangeError
prototype object does not contain any methods of its own,RangeError
instances do inherit some methods through the prototype chain.
例子
使用RangeError
var check = function(num) { if (num MAX) { throw new RangeError('Parameter must be between ' + MIN + ' and ' + MAX); } }; try { check(500); } catch (e) { if (e instanceof RangeError) { // 处理越界错误 } }
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)