Upon investigation, I discovered the error was not happening on other browsers, and it seems to be a bug in Pale Moon.
Code: Select all
document.body.addEventListener('click', async function () {
async function usingThrow() {
throw Error('Using throw');
}
await usingThrow().catch(err => console.log('Caught: ' + err));
});
document.body.addEventListener('click', async function () {
async function usingPromiseReject() {
return Promise.reject('Using Promise.reject');
}
await usingPromiseReject().catch(err => console.log('Caught: ' + err));
});
Note this code also causes an error:Caught: Using Promise.reject
Caught: Error: Using throw
uncaught exception: Using Promise.reject
Code: Select all
document.body.addEventListener('click', async function () {
async function usingPromiseReject() {
return Promise.reject('Using Promise.reject');
}
await usingPromiseReject().catch(err => console.log('Caught: ' + err));
async function usingThrow() {
throw Error('Using throw');
}
await usingThrow().catch(err => console.log('Caught: ' + err));
});
Code: Select all
document.body.addEventListener('click', async function () {
async function usingThrow() {
throw Error('Using throw');
}
await usingThrow().catch(err => console.log('Caught: ' + err));
async function usingPromiseReject() {
return Promise.reject('Using Promise.reject');
}
await usingPromiseReject().catch(err => console.log('Caught: ' + err));
});
Additionally:
- The error happens only when using an event handler. There is no error if directly executing the code.
- For the code causing errors, sometimes there is no error on the first clicks.
Maybe a some point in the await call, the promise reject is converted to a throw, whereas it shouldn't be, as it is handled by the .catch(). And that "leftover throw" doesn't break execution, while still being logged.