What is a range error in javascript?
The Note: Parameters
Human-readable description of the error. options OptionalAn object that has the following properties: cause OptionalA property indicating the specific cause of the error. When catching and re-throwing an error with a more-specific or useful error message, this property can be used to pass the original error. fileName Optional
Non-standardThe name of the file containing the code that caused the exception lineNumber Optional Non-standardThe line number of the code that caused the exception ExamplesUsing RangeError (for numeric values)
Using RangeError (for non-numeric values)
Specifications
Browser compatibilityBCD tables only load in the browser See alsoThe DescriptionA This can be encountered when:
ConstructorRangeError() Creates a new Instance propertiesRangeError.prototype.message
Error message. Although ECMA-262 specifies that RangeError.prototype.name Error name. Inherited from RangeError.prototype.fileName Path to file that raised this error. Inherited from
RangeError.prototype.lineNumber Line number in file that raised this error. Inherited from RangeError.prototype.columnNumber Column number in line that raised this error. Inherited from RangeError.prototype.stack Stack trace. Inherited from
ExamplesUsing RangeError (for numeric values)function check(n) { if( !(n >= -500 && n <= 500) ) { throw new RangeError("The argument must be between -500 and 500.") } } try { check(2000) } catch(error) { if (error instanceof RangeError) { } } Using RangeError (for non-numeric values)function check(value) { if(["apple", "banana", "carrot"].includes(value) === false) { throw new RangeError('The argument must be an "apple", "banana", or "carrot".') } } try { check("cabbage") } catch(error) { if(error instanceof RangeError) { } } SpecificationsBrowser compatibility
See also
How do you fix a range error?The most common way to fix this error is to reduce the number of function calls, or to limit the number of variables that are created. Another option is to use a tracer debugger to keep track of the program's state and find the function that's causing the error.
What is type error in JavaScript?The TypeError object represents an error when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type. A TypeError may be thrown when: an operand or argument passed to a function is incompatible with the type expected by that operator or function; or.
What is uncaught range error?The Uncaught RangeError is caused when the browser's hardcoded stack size is exceeded and the memory is exhausted. So, always ensure that the recursive function has a base condition that can stop its execution.
What is eval error in JavaScript?The EvalError object indicates an error regarding the global eval() function. This exception is not thrown by JavaScript anymore, however the EvalError object remains for compatibility.
|