DEV Community

Omi
Omi

Posted on

1 1

Will it catch?🤯

Was just recovering from last Node.js blocking non-blocking stuff, I come to another JS injury called error-handling with promises.

This injury was again caused to me by not being able to distinguish between blocking and non-blocking code.

The below question is from javascript.info website.

What do you think? Will the .catch trigger? Explain your answer.

new Promise(function (resolve, reject) {
  setTimeout(() => {
    throw new Error("Whoops!");
  }, 1000);
}).catch(console.error);
Enter fullscreen mode Exit fullscreen mode

The hint: Look at the code like this:

new Promise(function (resolve, reject) 
// try {
{
  setTimeout(() => {
    throw new Error("Whoops!");
  }, 1000);
})
//} catch {
.catch(console.error);
// }
Enter fullscreen mode Exit fullscreen mode

Comment down your answer below!

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay