Created
July 21, 2019 22:55
-
-
Save johnborges/1f51c09b48db8e99cc11b7bd65e3246b to your computer and use it in GitHub Desktop.
Async Await Error Handling
This file contains 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
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