Last active
November 2, 2020 21:14
-
-
Save conartist6/d6df1dcceadc5c0101f64e0cef7ec999 to your computer and use it in GitHub Desktop.
Generator throw behavior
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
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