uncaughtException

48 views
Skip to first unread message

Angelo Chen

unread,
Jul 17, 2012, 8:16:52 PM7/17/12
to Express
Hi,

got some code to test out uncaught Exception, why following code not
got caught in the listener?

app.get "/uncaughtException", (req, res) ->
throw new Error("uncaught error");
res.send 'uncaughtException'

process.addListener "uncaughtException", (err) ->
console.log("Uncaught exception: " + err)

Sugarstack

unread,
Jul 18, 2012, 1:40:00 PM7/18/12
to expre...@googlegroups.com
Express might be catching that error. Iirc, it picks up errors you throw directly in middleware/routes. (As well as passing errors with next().)

If you throw an error indirectly though, it shouldn't be caught by express' error handler, and be picked up by your handler instead:

app.get("/uncaughtException", function (req, res) {
        setTimeout(function () {
                throw new Error("uncaught error");
        }, 1000);
        res.send('uncaughtException');
});

process.addListener("uncaughtException", function (err) {
        console.log("Uncaught exception: " + err);
});
Reply all
Reply to author
Forward
0 new messages