Created
August 8, 2016 22:27
-
-
Save mrister/c818871f4064deb606aa2cabdd309261 to your computer and use it in GitHub Desktop.
Throwing an error inside a genrator.
This file contains hidden or 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
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