Let's try to reject the promise inside of the JS `try/catch`. Will we catch the error in the `catch` block? (think well, then click for the answer and explanation)
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.