Skip to content

Instantly share code, notes, and snippets.

@conartist6
Last active November 2, 2020 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conartist6/d6df1dcceadc5c0101f64e0cef7ec999 to your computer and use it in GitHub Desktop.
Save conartist6/d6df1dcceadc5c0101f64e0cef7ec999 to your computer and use it in GitHub Desktop.
Generator throw behavior
const item = {
done: true,
value: null,
};
function* wrap(source) {
try {
yield* source;
} catch (e) {
// this never happens
process.exit(0);
} finally {
// this also never happens
process.exit(0);
}
}
const test = wrap({
[Symbol.iterator]: () => ({
next: () => item,
}),
});
test.throw('junk');
/**
>$ node --trace-uncaught test.js
test.js:6
function* wrap(source) {
^
junk
Thrown at:
at wrap (test.js:6:15)
at test.js:24:11
>$ echo $?
1
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment