LearnFrenzy
Sign in Take a free test

Promises · Find the Error · Question 8

Error: a rejection nobody handles Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
function connect() {
  return Promise.reject(new Error("Database connection refused"));
}
connect().then(() => console.log("connected"));
console.log("server starting…");
  • A It prints server starting… and connected
  • B It prints only server starting…
  • C It prints server starting…, then Node.js stops with the unhandled rejection: add .catch(…) Correct
  • D SyntaxError
Correct Answer: Option C

then without a rejection handler passes the rejection on, and nothing catches it. Node.js treats unhandled rejections as fatal errors.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links