Weird behavior with Promise throwing “Unhandled promise rejection” error

耗尽温柔 提交于 2019-11-28 11:45:00

In order to be considered handled, rejected promises should be synchronously chained with then(..., ...) (2 arguments) or catch(...).

promise.then(() => console.log('ok')) is a separate promise that wasn't chained with catch(...), so rejected promise will result in unhandled rejection.

If I'm in any other page (like stackoverflow.com) it throws the exception

This isn't an exception, it doesn't prevent a script from running normally. The way unhandled rejections are treated depends on Promise implementation. Chrome implementation results in Uncaught (in promise) console error by default.

That it doesn't appear on some websites in Chrome means that a website set up unhandledrejection event handler that suppresses error output.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!