JavaScript · Senior · Question 47 of 75
Why pass the cause option to Error?
try { await save(); }
catch (err) { throw new Error("Failed to save the order", { cause: err }); }- ✓Correct answer: To keep the original error and not lose the root cause
- 2To send the error to a monitoring system automatically
- 3To stop the error from propagating further up the call stack
Explanation
Wrapping errors adds application-level context, and cause keeps the low-level error with its stack. DevTools and many monitoring systems show the whole chain of causes.