Node.js · Middle · Question 25 of 75

Why is it useful to pass cause when re-throwing an error?

try {
  await db.query(sql);
} catch (err) {
  throw new Error("Failed to load orders", { cause: err });
}

Explanation

Node.js prints the cause chain in stack traces. You get both the business context and the low-level reason.

Further reading

Problem with a question

Node.js · Middle · question 25

Test yourself

Take the Node.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz