Created
August 6, 2010 19:20
-
-
Save indexzero/511834 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'), | |
http = require('http'); | |
process.on('uncaughtException', function (err) { | |
sys.puts('Caught exception: ' + err); | |
}); | |
// Simple Example | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.write('Throwing exception') | |
res.end(); | |
throw new Error(); | |
}).listen(8080); | |
// Type Error | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.write('Throwing exception') | |
res.end(); | |
var myObj = {}; | |
myObj.doesntExist(); | |
}).listen(8081); |
Hmmm.... you're right. But the uncaughtException event is all about your request / response then why not just:
http.createServer(function (req, res) { try { // Entry point for all your server logic } catch (err) { // Respond to client based on error } });
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, but this leaves the client hanging..