Skip to content

Instantly share code, notes, and snippets.

@miensol
Created June 14, 2014 09:13
Show Gist options
  • Save miensol/d5dd0e6d46c05f51f0ed to your computer and use it in GitHub Desktop.
Save miensol/d5dd0e6d46c05f51f0ed to your computer and use it in GitHub Desktop.
generator receiving exceptions
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