Wrap your async code in a try/catch block to handle errors gracefully.
async function fetchData() {
try {
const response = await fetch('https://api.example.com/data');
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
}
}
fetchData();
Tags: intermediate, JavaScript, Async/Await, Error Handling