DEV Community

loading...
Cover image for JS Test #9: Promise.reject + try/catch

JS Test #9: Promise.reject + try/catch

Coderslang: Become a Software Engineer
Teaching you to code at js.coderslang.com - JavaScript, HTML, CSS, Node.js, React.js, React Native
Originally published at learn.coderslang.com ・1 min read

Will we catch the error in the catch block?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Regular try/catch blocks only catch errors that appear in the synchronous code.

As the Promise in the second line doesn’t have its own asynchronous .catch block, the rejection will be left unhandled.

An UnhandledPromiseRejectionWarning will be raised and the code inside of the regular catch block will not be executed.


ANSWER: The error will not be caught and the message the error was caught! will NOT be logged to the console.

Discussion (1)

Collapse
wangjing013 profile image
wangjing013

nice