Last active
August 29, 2015 14:08
-
-
Save nicholascloud/84f768e56c702ecb9c4c to your computer and use it in GitHub Desktop.
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
function asyncFunction(cb) { | |
process.nextTick(function () { | |
try { | |
var json = JSON.parse('{}'); | |
cb(null, json); | |
} catch (e) { | |
cb(e); | |
} | |
}); | |
} | |
asyncFunction(function (err) { | |
console.log(arguments); | |
throw new Error('should never happen, right?'); | |
}); | |
/* console output | |
/U/n/tmp$ node asynctrycatch.js | |
{ '0': null, '1': {} } | |
{ '0': [Error: should never happen, right?] } | |
/Users/nicholascloud/tmp/asynctrycatch.js:14 | |
throw new Error('should never happen, right?'); | |
^ | |
Error: should never happen, right? | |
at /Users/nicholascloud/tmp/asynctrycatch.js:14:9 | |
at /Users/nicholascloud/tmp/asynctrycatch.js:7:7 | |
at process._tickCallback (node.js:419:13) | |
at Function.Module.runMain (module.js:499:11) | |
at startup (node.js:119:16) | |
at node.js:906:3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment