aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/global_objects/rangeerror/index.html
blob: 154049adca1d12932ef2921a03797c6c87f62056 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
title: RangeError
slug: Web/JavaScript/Reference/Global_Objects/RangeError
tags:
  - Error
  - JavaScript
  - Object
  - RangeError
translation_of: Web/JavaScript/Reference/Global_Objects/RangeError
---
<div>{{JSRef}}</div>

<p>El objeto <code><strong>RangeError</strong></code> indica un error cuando un valor no se encuentra dentro de un rango de valores permitidos.</p>

<h2 id="Sintaxis">Sintaxis</h2>

<pre class="syntaxbox"><code>new RangeError([<var>message</var>[, <var>fileName</var>[, <var>lineNumber</var>]]])</code></pre>

<h3 id="Parámetros">Parámetros</h3>

<dl>
 <dt><code>message</code></dt>
 <dd>Opcional. Mensaje de error</dd>
 <dt><code>fileName</code> {{non-standard_inline}}</dt>
 <dd>Opcional. Nombre del fichero que contiene el código donde se produjo el error</dd>
 <dt><code>lineNumber</code> {{non-standard_inline}}</dt>
 <dd>Opcional. Número de línea de código donde se produjo el error</dd>
</dl>

<h2 id="Descripción">Descripción</h2>

<p>Se lanza un <code>RangeError</code> cuando se pasa como parámetro a una función un número que no está dentro del rango que dicha función permite. Esto puede ocurrir cuando se intenta crear un array  con una longitud inválida con el constructor {{jsxref("Array")}}, o al pasar valores inválidos a los métodos numéricos {{jsxref("Number.toExponential()")}}, {{jsxref("Number.toFixed()")}}{{jsxref("Number.toPrecision()")}}.</p>

<h2 id="Propiedades">Propiedades</h2>

<dl>
 <dt>{{jsxref("RangeError.prototype")}}</dt>
 <dd>Permite añadir propiedades a objetos <code>RangeError</code>.</dd>
</dl>

<h2 id="Métodos">Métodos</h2>

<p><code>RangeError</code> no contiene métodos, pero hereda a través de la <a href="https://developer.mozilla.org/es/docs/Web/JavaScript/Herencia_y_la_cadena_de_protipos">cadena de prototipos</a>.</p>

<h2 id="Instancias_de_RangeError">Instancias de <code>RangeError</code></h2>

<h3 id="Propiedades_2">Propiedades</h3>

<div>{{page('/es/docs/Web/JavaScript/Reference/Global_Objects/RangeError/prototype', 'Propiedades')}}</div>

<h3 id="Métodos_2">Métodos</h3>

<div>{{page('/es/docs/Web/JavaScript/Reference/Global_Objects/RangeError/prototype', 'Métodos')}}</div>

<h2 id="Ejemplos">Ejemplos</h2>

<h3 id="Utilizando_RangeError">Utilizando <code>RangeError</code></h3>

<pre class="brush: js">var check = function(num) {
  if (num &lt; MIN || num &gt; MAX) {
    throw new RangeError('El parámetro debe estar entre ' + MIN + ' y ' + MAX);
  }
};

try {
  check(500);
}
catch (e) {
  if (e instanceof RangeError) {
    // TODO: Manejar el error de rango
  }
}
</pre>

<h2 id="Especificaciones">Especificaciones</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Especificación</th>
   <th scope="col">Estado</th>
   <th scope="col">Comentario</th>
  </tr>
  <tr>
   <td>{{SpecName('ES3')}}</td>
   <td>{{Spec2('ES3')}}</td>
   <td>Definición inical.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.11.6.2', 'RangeError')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-native-error-types-used-in-this-standard-rangeerror', 'RangeError')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidad_en_navegadores">Compatibilidad en navegadores</h2>

{{Compat("javascript.builtins.RangeError")}}

<h2 id="Vea_también">Vea también</h2>

<ul>
 <li>{{jsxref("Error")}}</li>
 <li>{{jsxref("RangeError.prototype")}}</li>
 <li>{{jsxref("Array")}}</li>
 <li>{{jsxref("Number.toExponential()")}}</li>
 <li>{{jsxref("Number.toFixed()")}}</li>
 <li>{{jsxref("Number.toPrecision()")}}</li>
</ul>