Error objects: RangeError, TypeError, ValueError

David Herman dherman at
Tue Nov 29 14:06:19 PST 2011

On Nov 22, 2011, at 10:14 AM, Brendan Eich wrote:

> On Nov 22, 2011, at 9:37 AM, Allen Wirfs-Brock wrote:
>> Range error actually has fairly limited usage in the current specification.  Enough so, that it arguably doesn't carry its weight as one of the very few available exceptions "classes".    I think we could reasonably drop the "numeric" from its prose description and use it for all (new) situations where a provided value is of the correct "type" but outside the set of acceptable values of that type. 
> Pedants and wannabes like me will object to "Range" instead of "Value" (codomain vs. domain :-P). But agreed, we could use RangeError in more places; we could do worse.

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.)

An interval implies an ordering. It can be specified by lower and upper bounds. Using RangeError for "does not fall in the expected set of values" stretches the meaning of "range" beyond its normal meaning, which is "does not fall in the expected *interval* of values."

TypeError is a much more appropriate error here. "This value does not fall in the expected set of values" is the way TypeError is used pervasively in JS.


More information about the es-discuss mailing list