I'm running into an issue where I need to handle errors within a promise using async/await, but the current code keeps resulting in an "Uncaught Error ..."
function makeMistake() {
var promise = new Promise(function(resolve, reject){
setTimeout(function() {
throw new Error("Oops! An error occurred.");
resolve('Hello from makeMistake function');
}, 1000);
});
return promise;
}
async function waitForError() {
try {
await makeMistake();
} catch(e) {
console.log ('*****Successfully caught the error! *****');
}
}
waitForError()