async function example() {
try {
const result = await promise;
return result;
} catch (error) {
console.error(error);
}
}
try/catch with async/await provides several advantages: 1) Can catch both synchronous and asynchronous errors in the same block, 2) More familiar syntax for developers coming from other languages, 3) Makes error handling code more readable and maintainable, 4) Allows for more granular error handling within the function, 5) Better scope management for variables needed in both try and catch blocks, 6) Enables using existing error handling patterns in async code.