2017-06-26 41 views
0

我有我的代碼被觸發警告的錯誤:我可以使nodejs在未處理的承諾拒絕中終止嗎?

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.

有沒有什麼辦法,使節點終止,當這些發生的呢?

回答

2

process將發出這些的unhandledRejection event,所以:

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

代替'拋錯誤的;'也許將是很好的'process.exit(1)'。只是爲了關注將來會發生的事情,正如消息所示:'Node.js處理的非零退出代碼.' –

+1

@DiegoZoracKy:拋出錯誤已經導致退出時出現非零代碼。它還顯示有用的信息。 – Ryan

相關問題