Opens in a new tab
A picture of Jeff Brigman
I CODE TODAY FOR
A BETTER TOMORROW

Glossary Term

Generator.prototype.throw()

2 tags 1 category

The throw() method of Generator instances acts as if a throw statement is inserted in the generator’s body at the current suspended position, which informs the generator of an error condition and allows it to handle the error, or perform cleanup and close itself.

The throw() method, when called, can be seen as if a throw exception; statement is inserted in the generator’s body at the current suspended position, where exception is the exception passed to the throw() method. Therefore, in a typical flow, calling throw(exception) will cause the generator to throw. However, if the yield expression is wrapped in a try…catch block, the error may be caught and control flow can either resume after error handling, or exit gracefully.

Syntax example: generatorInstance.throw(exception)

Term Connections

Explore related terms connected by shared tags, shared categories, and relationship phrases. This map loads only when it comes into view.

Loading term connections…