> I've heard that generators helps to catch errors but didn't seen any good > explanation how to do that, if anyone knows such an article please post > link here >
With the galaxy library, you just use try/catch to handle errors with generators. The model is the same as async/await in other languages: you declare your async functions with function* and you call async functions with yield. So your code is made of function* functions calling other function* function through yield and exceptions propagate as you'd expect them to through these call chains. Typical galaxy code structure looks like: function* f1(request, response) { try { yield f2(request, response); } catch (ex) { handleError(ex); } } function* f2(request, response) { yield f3(request, response); yield f4(request, response); } function* f3(request, response) { yield f5(request, response); ... } function* f4(request, response) { ... } function* f5(request, response) { ... } And ex.stack gives you both the "async" stack trace (f1 -> f2 -> f3 -> ...) and the raw stack trace. IMO the "standard" node guidelines are suitable for people who develop low-level I/O libraries. If you are writing applications rather than libraries you are much better off with "non-standard" solutions that give you higher level constructs (sync style), robust error handling, etc. Note: I designed galaxy but we are not using it directly. We are using it through streamline which gives us a leaner/cleaner syntax and also the option to toggle between 3 runtime options (callbacks, fibers, generators). Bruno -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.