I am new to node.js and am trying to experiment with basic stuff.
My code is this
var http = require(\"http\");
http.createServer(function(request,
You can use
process.on('uncaughtException', function(e){
console.log(e);
});
To handle uncaught exceptions. Any unhandled exception from the web server could be caught like this.
You can do this by handling the error event on the server you are creating. First, get the result of .createServer()
.
var server = http.createServer(function(request, response) {
Then, you can easily handle errors:
server.on('error', function (e) {
// Handle your error here
console.log(e);
});
The error is emitted in the listen() method. The API documentation includes an example just for your situtation.
Print stacktrace of uncaught exceptions using following code.
process.on('uncaughtException', function( err ) {
console.error(err.stack);
});