Question 8
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
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!