I am working with Promises and found that when rejecting is recommended to pass an Error()
object as argument in order to enable error handling.
I find some examples where a new Error()
is given and some others where only Error()
is passed.
After testing several cases I just do not find any difference between one usage and other, as seen here where both rejects seem to behave exactly the same:
const p = new Promise((resolve, reject) => {
setTimeout(reject, 1000, Error("Nope..."));
//setTimeout(reject, 1000, new Error("Nope..."));
});
p.then(val => { console.log(val) })
.catch(error => { console.error(error.message) });
In this case, which practical difference is between both error handling ways?