function abc() {
try {
setTimeout(() => {
console.log('inside timeout!!');
throw new Error('Somehting went wrong!!');
}, 1000);
} catch (err) {
console.log('Gonna catch it here and throw is again', err);
throw new Error(err);
}
}
try {
abc();
} catch (err) {
console.log('err caught here', err);
}
How to catch the error ? Where should I wrap my code with try/catch ? Even with promise why catch block didn't catch the error.
async function abc() {
setTimeout(() => {
throw new Error();
}, 1000);
}
try {
abc();
} catch (err) {
console.log('err is ', err);
}