Skip to content

Instantly share code, notes, and snippets.

@miensol
Created June 14, 2014 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miensol/f740e31ccc73283809a5 to your computer and use it in GitHub Desktop.
Save miensol/f740e31ccc73283809a5 to your computer and use it in GitHub Desktop.
generator throwing excaptions
var throwing = function *(){
console.log('Generator entered, yielding first value');
yield 1;
console.log('Generator asked for second value - will go bum');
throw new Error("You can only call this generator once, sorry!");
console.log('Will never get here');
yield 3;
};
var throwingGenerator = throwing();
throwingGenerator.next();
try {
throwingGenerator.next();
} catch (e) {
console.error(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment