Skip to content

Instantly share code, notes, and snippets.

@dbayarchyk
Last active October 1, 2019 11:45
Show Gist options
  • Save dbayarchyk/bd48e7587de36b4366b0f8adbbef45d1 to your computer and use it in GitHub Desktop.
Save dbayarchyk/bd48e7587de36b4366b0f8adbbef45d1 to your computer and use it in GitHub Desktop.
Async/await without try/catch in JavaScript - combineCatchHandler.js
async function fetchAndUpdatePosts() {
let posts;
try {
posts = await fetchPosts();
doSomethingWithPosts(posts); // throws an error
} catch {
// Now it handles errors from fetchPosts and doSomthingWithPosts.
console.log('error in fetching posts');
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment