Skip to content

Instantly share code, notes, and snippets.

@johnborges
Created July 21, 2019 22:55
Show Gist options
  • Save johnborges/1f51c09b48db8e99cc11b7bd65e3246b to your computer and use it in GitHub Desktop.
Save johnborges/1f51c09b48db8e99cc11b7bd65e3246b to your computer and use it in GitHub Desktop.
Async Await Error Handling
run().
catch(function handleError(err) {
err.message; // Oops!
}).
// Handle any errors in `handleError()`. If the error handler
// throws an error, kill the process.
catch(err => { process.nextTick(() => { throw err; }) });
async function run() {
await Promise.reject(new Error('Oops!'));
// alternative
// Note that this is `return`, not `await`
return Promise.reject(new Error('Oops!'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment