Is there a way to ignore asynchronous errors while calling a function?
function synchronous() {
console.log('Nice feature');
throw new Error('Async Error');
}
try {
synchronous();
console.log('Succeeded');
} catch (e) {
console.log('Caught');
}
Console Output:
Nice feature
Caught
async function asynchronous() {
console.log('Nice feature');
throw new Error('Async Error');
}
try {
asynchronous();
console.log('Succeeded');
} catch (e) {
console.log('Caught');
}
Console Output:
Nice feature
Uncaught (in promise) Error: Async Error at asyncFunc
two options:
(async () => {
try {
await asynchronous();
console.log('Succeeded');
} catch (e) {
console.log('Caught');
}
});
or
asynchronous()
.then(r => {
console.log('succeeded');
})
.catch(e => {
console.log('caught');
});
I'm not sure if that answers your question, but if "await" for the result of calling asynchronous() function, the error will not occur