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 });
}- ✓Correct answer: It adds context while keeping the original error and its stack for debugging
- 2It sends the error to the client automatically
- 3It makes the error non-fatal
Explanation
Node.js prints the cause chain in stack traces. You get both the business context and the low-level reason.