A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw below:

Generator.prototype.throw() - JavaScript | MDN

Generator.prototype.throw()

Baseline Widely available

El método throw() reanuda la ejecución de un generador al lanzar un error en éste y regresar un objeto con las dos propiedades done y value.

Sintaxis Parámetros
excepción

La excepción a lanzar. Al hacer depuración, es útil que la excepción cumpla con instanceof Error.

Valor de retorno

Un Object con dos propiedades:

Examples Using throw()

The following example shows a simple generator and an error that is thrown using the throw method. An error can be caught by a try...catch block as usual.

function* gen() {
  while (true) {
    try {
      yield 42;
    } catch (e) {
      console.log("Error caught!");
    }
  }
}

var g = gen();
g.next();
// { value: 42, done: false }
g.throw(new Error("Something went wrong"));
// "Error caught!"
// { value: 42, done: false }
Especificaciones Compatibilidad con navegadores See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4