Skip to content

Instantly share code, notes, and snippets.

@mrister
Created August 8, 2016 22:27
Show Gist options
  • Save mrister/c818871f4064deb606aa2cabdd309261 to your computer and use it in GitHub Desktop.
Save mrister/c818871f4064deb606aa2cabdd309261 to your computer and use it in GitHub Desktop.
Throwing an error inside a genrator.
function * genThrow() {
yield 'egg';
throw new Error('I am out of eggs');
}
try {
const eggy = genThrow();
eggy.next();
// second call invokes throw
eggy.next();
} catch (e) {
console.log(e); // Error: I am out of eggs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment