Created
November 12, 2018 15:20
-
-
Save everettcaleb/72352eba8fc78a33bdd6ea67c21ef102 to your computer and use it in GitHub Desktop.
Example for handling unhandled rejected promises
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
Unhandled Rejection | |
Reason: | |
Error | |
at funcC (/Users/everettcaleb/Desktop/test.js:11:9) | |
at funcB (/Users/everettcaleb/Desktop/test.js:7:9) | |
at funcA (/Users/everettcaleb/Desktop/test.js:3:9) | |
at main (/Users/everettcaleb/Desktop/test.js:23:3) | |
at Object.<anonymous> (/Users/everettcaleb/Desktop/test.js:24:3) | |
at Module._compile (internal/modules/cjs/loader.js:688:30) | |
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) | |
at Module.load (internal/modules/cjs/loader.js:598:32) | |
at tryModuleLoad (internal/modules/cjs/loader.js:537:12) | |
at Function.Module._load (internal/modules/cjs/loader.js:529:3) | |
Promise: | |
Promise { | |
<rejected> Error | |
at funcC (/Users/everettcaleb/Desktop/test.js:11:9) | |
at funcB (/Users/everettcaleb/Desktop/test.js:7:9) | |
at funcA (/Users/everettcaleb/Desktop/test.js:3:9) | |
at main (/Users/everettcaleb/Desktop/test.js:23:3) | |
at Object.<anonymous> (/Users/everettcaleb/Desktop/test.js:24:3) | |
at Module._compile (internal/modules/cjs/loader.js:688:30) | |
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) | |
at Module.load (internal/modules/cjs/loader.js:598:32) | |
at tryModuleLoad (internal/modules/cjs/loader.js:537:12) | |
at Function.Module._load (internal/modules/cjs/loader.js:529:3) } |
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
async function funcA() { | |
await funcB() | |
} | |
async function funcB() { | |
await funcC() | |
} | |
async function funcC() { | |
throw new Error() | |
} | |
(function main() { | |
process.on('unhandledRejection', (err, promise) => { | |
console.error('Unhandled Rejection') | |
console.error('Error:') | |
console.error(err) | |
console.error('Promise:') | |
console.error(promise) | |
}); | |
funcA() | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment