In the accepted answer to this question the guy recommends against using domains with throwing exceptions from them because, he says, it will cause memleaks and instability. But this is the way I was going to use domains. Now I'm confused. Is he right?
Is it safe to use domains actually?
119 Views Asked by Andrey Kon At
2
Unlike that answer asserts, there is no guarantee that it will cause memory leaks and instability. But it is hard to guarantee that you can handle the exception without causing memory leaks and instability.
I believe the core of the confusion around exception handling stems from this wording from the Node.js documentation:
http://nodejs.org/api/domain.html
In reality, there's nothing special about JavaScript that makes exceptions particularly dangerous. The fact is, exceptions have potential to be dangerous in any language. The point is to consider carefully what side-effects your application is causing, and whether you're doing anything that could be dangerous if it were to stop half-way through (hint: you probably are).
This design guide from Joyent makes the distinction between "programmer errors" and "operational errors". In answer of your question, this guide advocates not handling programmer errors (including reading a property of undefined), and asserts that since Domains and
process.on('uncaughtException')are primarily geared toward these kinds of errors, they should be avoided.