Last active
October 1, 2019 11:45
-
-
Save dbayarchyk/bd48e7587de36b4366b0f8adbbef45d1 to your computer and use it in GitHub Desktop.
Async/await without try/catch in JavaScript - combineCatchHandler.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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