I read somewhere that it should be possible to catch an error that was thrown in the promise using Promise.catch, but I'm not quite getting it to work..
Here is a minimal working(or not) example I'm having issues with. I've tried to catch the error using try-catch and using Promise.catch, but neither of them seem to work. Am I missing something here?
{
function throwingFunction() {
return new Promise(() => {
setTimeout(() => {
throw new Error();
}, 1000);
})
}
(async() => {
try {
await throwingFunction().catch(error => console.log("then-catch"));
} catch(error) {
console.log("try-catch");
}
})()
}
The problem I am trying to solve is the following: I'm writing some tests for an application. The application throws some errors that I can then use as feedback when testing the ui.