In the below code, if the function call()
is being called with await, then my console is not logging the "finished" value. So this basically means that due to the uncaught error, the function is being stopped right at the await line and the error handling code should come into place.
function call()
{
return Promise.reject("done")
}
React.useEffect(()=>{
async function check(){
const x = await call();
console.log(x);
console.log("finished");
};
check();
},[])
However, if I'm using fetch()
then even with an error, the below lines are being executed and console logged.
React.useEffect(()=>{
async function check(){
const x = await fetch("https://www.thecocktaildb.com/api/json/v1/1/");
console.log(x);
console.log("finished");
};
check();
},[])
Why is there a different behavior for fetch errors and function call errors?