Error objects: RangeError, TypeError, ValueError

John J Barton johnjbarton at johnjbarton.com
Tue Nov 29 21:18:15 PST 2011


On Tue, Nov 29, 2011 at 8:38 PM, David Herman <dherman at mozilla.com> wrote:
> 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?

Why discuss any of these when the important and useful information is
in the Error object content? Save some paint for the other side of the
shed ;-)

jjb


More information about the es-discuss mailing list