by camus2 · 12y ago · 0 comments
The hardest stuff in JS is that :
function F(){throw "error"}
try{setTimeout(F,1000)}catch(error){ console.log("error")}
we cant catch async errors outside the async callback , will generators fix this ? ( by the way , that's why you should never throw any error yourself in js ).You can catch async errors with generators and promises; see e.g. the linked post, or http://jlongster.com/A-Study-on-Solving-Callbacks-with-JavaS...
You can inject an exception into a generator via the throw method[0], and it'll be raised at the yield, as if `yield` had thrown[1].
JS exception handling facilities are still crap, though.
[0] http://wiki.ecmascript.org/doku.php?id=harmony:generators#me...
[1] http://wiki.ecmascript.org/doku.php?id=harmony:generators#in...
I think you can catch async errors if you call the throw method on the generator.
http://wiki.ecmascript.org/doku.php?id=harmony:generators#me...