As is mentioned in the answer to this post - if you have an un-caught exception your best approach is to let the process die and recover from there - otherwise you have no idea what the current state of the application is.
Because you did not catch the Exception, it suggests that the application does not know what went on. To get around this - you design your application in lots of little chunks rather than in one process.
This takes a slight hit on performance (RPC vs in process communication) but it means you get to sleep easy whilst tiny chunks go wrong, restart and everything is fine because they never maintain state within themselves (use Redis for that)...
If you really want to catch an exception within a request and then call end() on the request you must use a closure with access to the response like so:
// a method that will catch an error and close the response
var runFunctionSafely = function(res, tryFunction){
try{
tryFunction();
}
catch(error){
console.log('there was an error, closing the response...');
console.log(error);
res.end();
}
}
app.get('/test', function(req, res, next) {
runFunctionSafely(res, function(){
throw new Error('this is a problem');
})
});