You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(node:48446) UnhandledPromiseRejectionWarning: This is fine
(node:48446) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:48446) [DEP0018] 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.
第一个问题 未处理的rejections
unhandledrejection
事件,可以直接在window对象上添加监听器Promise.reject(new Error('This is fine'))
,在回调函数里的reason
就是那个error实例。所以在调用reject时,传递详细明确的错误类型或者信息进去是很重要的。process
触发的warn
事件,来获取关于未处理的rejections的信息。第二个问题 steam中未处理的错误事件
额外的炸弹: JSON.parse()
try/catch
包起来或者放入promise
,在处理generator函数或者async函数时,也是同样的道理。不然的话,像如下代码就会杀掉你的程序:*Sync()
函数以及JSON.parse()
时,一定要用try/catch
包起来或者放入promise中。The text was updated successfully, but these errors were encountered: