2017-10-28T15:30:00Z||2017-10-28T15:30:00Z
Node.js使用Promise时遇到这种未处理异常会提示:
UnhandledPromiseRejectionWarning: Unhandled promise rejection
DeprecationWarning: Unhandled promise rejections are
deprecated. In the future, promise rejections that are not handled
will terminate the Node.js process with a non-zero exit code.
但是具体是哪个Promise的哪个问题却没有提示,让开发人员非常头疼。这个问题业界一直都有所讨论。目前最简单的方法就是:
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection:', p, 'reason: ', reason);
});
如果是在使用bluebird,还可以尝试打开更详细的堆栈信息,运行时打开BLUEBIRD_LONG_STACK_TRACES
:
BLUEBIRD_LONG_STACK_TRACES=1 BLUEBIRD_WARNINGS=1 node app.js