Skip to content

Instantly share code, notes, and snippets.

@samyakbhuta
Created August 12, 2011 06:28
Show Gist options
  • Save samyakbhuta/1141573 to your computer and use it in GitHub Desktop.
Save samyakbhuta/1141573 to your computer and use it in GitHub Desktop.
Catching an uncaughtException in express.js based server
var express = require('express');
process.on('uncaughtException', function(err) {
console.log( " UNCAUGHT EXCEPTION " );
console.log( "[Inside 'uncaughtException' event] " + err.stack || err.message );
});
anHTTPServer = express.createServer(function (req,res){
if (Math.random() > 0.9) throw new Error('fail!');
res.send("Hello World : Express!!");
});
anHTTPServer.listen(3000);
@alvaropaco
Copy link

You have a problem with this approach. Basically, is a exception occurs and you catch this on your proccess.on you will perform the callback to any other requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment