我試圖得到錯誤處理運行與快遞,而不是看到「錯誤!!!」的迴應。就像我期望的那樣,我在控制檯上看到「一些異常」,然後這個過程就被終止了。這是錯誤處理應該如何設置,如果有的話是否有另一種方法來捕捉錯誤?表達式js錯誤處理
var express = require('express');
var app = express();
app.use(function(err, req, res, next) {
console.log("error!!!");
res.send("error!!!");
});
app.get('/', function(request, response) {
throw "some exception";
response.send('Hello World!');
});
app.listen(5000, function() {
console.log("Listening on 5000");
});
對於未來的人來說,3.x => 4.x遷移過程不推薦使用app.router;請參閱https://github.com/strongloop/express/wiki/Migrating-from-3.x-to-4.x。 –