ECMAScript question detail
Error Cause
The cause property is added to the Error() constructor as an extra parameter which allow errors to be chained similar to Java-like stack traces in error chains.
In the below example, let's catch an error from JSON processing and re-throw it with a new meaningful message along with the original cause of the error.
function processUserData(arrayData) {
return arrayData.map(data => {
try {
const json = JSON.parse(data);
return json;
} catch (err) {
throw new Error(
`Data processing failed`,
{cause: err}
);
}
});
}