Indian problemsOne of the remaining shortcomings of Node.js, which frightened backend developers from using Node.js, was the fact that an uncaught exception in the stream ruined the worker, and all clients who were waiting for a response from him did not receive anything.
tl; dr There is a new API for asynchronous try \ catch. From the article you can copy an example and play around.
Consider the situation:
We have a request to the web server of the node, while processing data received from the database, there is some kind of problem (invalid parameters that cannot be validated, a rack with the database has fallen off, or just carelessness) - an error occurs. Before the start of our request, there were 5 requests from other customers and the page started loading. After the request received 10 more requests from other users. And here she is a mistake, in the depths of callbacks of one of the parallel requests. All 16 requests fall off. Innocents suffer.
It would be possible to create a separate worker for each request, but this is very expensive in terms of resources.
You can wrap a dangerous piece in try \ catch, but on complex systems it is simply impossible.
You can hope at your own risk that everything will be right and the losses will be small.
')
Not canonical.
Yes come domainSo, in version 0.8 a silver bullet appeared, an error trapping wizard, an unsurpassed
Domain . At the moment, the API is in unstable status, but you can already use it.
A simple example:
var domain = require('domain'), server = require('http').createServer(function(req, res) {
By running this simple script, when you go to the root address, everything is OK, but if you go to the / error address, you will see an error log in the console, and a correct message in the browser that something went wrong and the status is 500.
PS Sorry for the spelling and punctuation, I will be happy to indicate errors.