Last active
August 29, 2015 14:14
-
-
Save deepak/f41c622efc574ebab7c1 to your computer and use it in GitHub Desktop.
cannot throw error in generator
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
works if generator is not calling another function ? | |
example from http://davidwalsh.name/es6-generators-dive | |
similar example at https://gist.github.com/deepak/9a7337d7a641f8af9c8b |
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 *foo() { | |
try { | |
var x = yield getThree(); | |
console.log( "x: " + x ); // may never get here! | |
} | |
catch (err) { | |
console.log(err.toString()); | |
} | |
} | |
function getThree() { | |
it.next(3); | |
} | |
var it = foo(); | |
var res = it.next(); | |
console.log(res); | |
it.throw("Oops!"); | |
// output | |
// Error: Generator is already running | |
// {"done":true} |
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
var it = foo(); | |
function* foo() { | |
try { | |
var x = yield 3; | |
console.log( "x: " + x ); // may never get here! | |
} | |
catch (err) { | |
console.log( "Error: " + err ); | |
} | |
} | |
var res = it.next(); | |
console.log(res); | |
it.throw("Oops!"); | |
// output | |
// {"value":3,"done":false} | |
// Error: Oops! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
similar to https://gist.github.com/deepak/9a7337d7a641f8af9c8b