Created
June 14, 2014 09:13
-
-
Save miensol/d5dd0e6d46c05f51f0ed to your computer and use it in GitHub Desktop.
generator receiving exceptions
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 catchingGenerator = function *(){ | |
console.log('I will stop when you tell me about error'); | |
var error = null; | |
while(error === null){ | |
try { | |
var value = yield null; | |
console.log("Got value from you: %s", value); | |
}catch(e){ | |
error = e; | |
} | |
} | |
console.log('Got error from you: %s. Goodbye!', error); | |
}; | |
var throwingGenerator = catchingGenerator(); | |
throwingGenerator.next("Wait for error"); | |
throwingGenerator.next("I will throw in a moment!"); | |
throwingGenerator.throw("This is the end"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment