The problem I am facing is that somewhere in the code I am working with there is an error that I cannot catch. The simplest example of this would be the code below:
try {
new Promise((res, rej) => rej(new Error('You cannot catch me. Haha')));
} catch (err) {
conosle.error(err);
}
I don’t want to alter the code much. I want to be able to catch and ignore some errors like that. I am trying to replace Promise
by wrapping it so that i can catch all errors of that sort.
I have tried asking ChatGPT and it doesn’t help much, so Googling will most probably not help also.
2
Answers
After some fighting and effort I came up with this solution:
This solution catches all errors generated inside of promises and ignores errors that
errorIgnorer
function "filters".Promises have their own catch clause. You can catch it through that.