Error objects: RangeError, TypeError, ValueError

David Herman dherman at mozilla.com
Tue Nov 29 20:38:24 PST 2011


On Nov 29, 2011, at 2:34 PM, Allen Wirfs-Brock wrote:

> On Nov 30, 2011, at 9:06 AM, David Herman wrote:
> 
>> And then pedants like me will object to your interpretation of "range" in this context. :) The way "range" is being used is as an "interval", which is common in CS, and not the same as the mathematical tradition. (In fact, there are multiple conflicting uses of the word "range" in math.)
> 
> Except that ES doesn't even consistently follow that definition.  For example:
> 
> 15.4.2.2: If the argument len is a Number and ToUint32(len) is equal to len, then the length property of the newly constructed object is set to ToUint32(len). If the argument len is a Number and ToUint32(len) is not equal to len, a RangeError exception is thrown.
> 
> new Array(1.2)
> RangeError on line 1: invalid array length

You could certainly argue that that should have been a TypeError, but the expected values are integers in the range [0, 2^32). There's still a reasonable intuition that "range" means "numeric interval". Why redefine RangeError to mean TypeError when we already have TypeError?

Dave

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111129/b4e504ee/attachment-0001.html>


More information about the es-discuss mailing list