Created
June 14, 2014 09:01
-
-
Save miensol/f740e31ccc73283809a5 to your computer and use it in GitHub Desktop.
generator throwing excaptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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