DEV Community

Cover image for JS Test #9: Promise.reject + try/catch
Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer

Posted on • Originally published at learn.coderslang.com

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

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.

Top comments (1)

Collapse
 
wangjing013 profile image
wangjing013

nice