Last active
May 10, 2020 23:54
-
-
Save zignd/98807b94a635990a227943596935dafc to your computer and use it in GitHub Desktop.
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 openDatabaseConnection() { | |
| const connection = { | |
| isOpen: true, | |
| hasPermissionToDelete: false | |
| } | |
| return connection; | |
| } | |
| async function example() { | |
| const connection = await openDatabaseConnection(); | |
| if (!connection.hasPermissionToDelete) { | |
| throw new Error("can't use connection, doesn't have permission to delete") | |
| } | |
| // ... | |
| } | |
| example().then(() => { | |
| console.log("Operation successfully completed") | |
| }).catch((err) => { | |
| console.error(new Error(`operation failed to complete: ${err.message}`)) | |
| }) | |
| // $ node throw-async.js | |
| // Error: operation failed to complete: can't use connection, doesn't have permission to delete | |
| // at /home/zignd/code/error-handling-nodejs/throw-async.js:20:19 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment