Created
August 8, 2016 22:24
-
-
Save mrister/0e9f422706eb3c38918696359a01143e to your computer and use it in GitHub Desktop.
Throwing an error to the generator function.
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 *genTestError() { | |
while (true) { | |
try { | |
var val = yield null; | |
console.log('value', val); | |
} catch (e) { | |
console.log('There was an error', e); | |
} | |
} | |
} | |
var test = genTestError(); | |
test.next(); | |
// Invoke the error by throwing it | |
test.throw(new Error('test error')); | |
// logs There was an error Error: test error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment