await async javascript catch code example
Example 1: catch errors async await javascript
try {
await fetchUserData(userId)
} catch (e) {
console.log('asynchronous error was caught!');
handleError(e);
}
Example 2: await and catch javascript
var response = await promisedFunction().catch((err) => { console.error(err); });
// response will be undefined if the promise is rejected
// this will work instead of using try...catch...