我可以让nodejs终止未处理的拒绝承诺吗?

时间:2017-06-26 01:25:33

标签: node.js

我的代码中有一个错误,触发了警告:

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.

当这些发生时,有没有办法让Node终止?

1 个答案:

答案 0 :(得分:7)

process会为这些发出unhandledRejection event,所以:

process.on('unhandledRejection', error => {
    throw error;
});