EDIT: Please see Edit-Start below,
I am receiving this error when I try to reject a promise: -
"VM168:3 Uncaught (in promise) I love You !!"
If you look at the example below you'll see that the THEN caters for both Resolve and Reject outcomes. If you remove the comment markers /* */ and run it again you'll see there is no error generated.
Why is this error occuring?
Example credit to w3schools: -
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Promise</h2>
<p>Wait 3 seconds (3000 milliseconds) for this page to change.</p>
<h1 id="demo"></h1>
<script>
const myPromise = new Promise(function(myResolve, myReject) {
setTimeout(function(){ myReject("I love You !!"); }, 3000);
});
/*
myPromise.then(function(value) {
document.getElementById("demo").innerHTML = value;
},
function(value) {
document.getElementById("demo").innerHTML = "Boom"+value;
});*/
</script>
<input typt="text"/>
</body>
</html>
Edit-Start
So the "Uncaught (in promise)" appears in the console as an Error and NOT a Warning yet all following instructions (post calling myReject) are executed. Probably as, IIRC, promises are held over to the next event loop by design.
So even if I try (see what I did there :-) to trap the error, I can't!
const myPromise = new Promise(function(myResolve, myReject) {
setTimeout(
function(){ try{
myReject("I love You !!");
} catch(err) {
console.log("Err = "+err.message)
}
}, 3000);
});
How marvellously consistent and retrospectively compatable :-(
At least the state of myPromise is set to Rejected. Thank heaven for small mercies!