【发布时间】:2012-07-16 04:12:36
【问题描述】:
我正在使用node-mongodb-native 驱动程序。我试过了
collection.findOne({email: 'a@mail.com'}, function(err, result) {
if (!result) throw new Error('Record not found!');
});
但是mongodb驱动发现了错误,express server被终止了。
这个案例的正确方法是什么?
=== 编辑===
我在 app.js 中有下面的代码
app.configure('development', function() {
app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
});
app.configure('production', function() {
app.use(express.errorHandler());
});
node_modules/mongodb/lib/mongodb/connection/server.js中的相关代码
connectionPool.on("message", function(message) {
try {
......
} catch (err) {
// Throw error in next tick
process.nextTick(function() {
throw err; // <-- here throws an uncaught error
})
}
});
【问题讨论】:
-
app是什么对象?它是http服务器、express服务器还是其他什么?