The new cause data property that you can add to a thrown Error
can be used to retain access to the original error caught in a promise rejection.
const sendLog = (...args) => console.log(...args);
async function fetchStuff() {
await fetch('http://doesnt.exist/stuff')
.catch(err => {
sendLog(err);
throw new Error('Loading stuff failed', { cause: err });
});
}
fetchStuff()
.catch(err => {
console.log(err);
console.log(err.cause);
});
标签:wide,Handling,console,log,err,JavaScript,Error,cause
From: https://www.cnblogs.com/Answer1215/p/18206199