Created
June 2, 2017 07:18
-
-
Save stelcheck/0d981e2b951b8c95a3487a733fde1925 to your computer and use it in GitHub Desktop.
require cache behaviour on throw
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
try { | |
require('./bad-require') | |
} catch (error) { | |
console.error('first error:', error.message) | |
} | |
try { | |
require('./bad-require') | |
} catch (error) { | |
console.error('second error:', error.message) | |
} |
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
require('./registry').register(__filename) | |
throw new Error('nein nein nein nein nein') // We provide five neins of availability |
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
const registry = {} | |
exports.register = function (name) { | |
if (registry[name]) { | |
throw new Error('already registered!') | |
} | |
registry[name] = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To test: run
node app.js