Imagine I have the following function:
const test = async () => {
const response = await axios.get('testurl');
return response;
}
And then I try to use the function like this:
try {
test();
} catch (error) {
// handle errors
}
Will the try-catch block actually catch the error if I call the test() function without an await in front of it in the try-catch block?
>Solution :
No. Without an await the calling function will not go to sleep and wait for the promise to resolve or error. It will continue running to its own completion.
Later, when the promise errors, the error will be unhandled.