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 }); }

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.

Further reading

Problem with a question

JavaScript · Senior · question 47

Test yourself

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

Take this quiz