Skip to content

Instantly share code, notes, and snippets.

@nicholascloud
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholascloud/84f768e56c702ecb9c4c to your computer and use it in GitHub Desktop.
Save nicholascloud/84f768e56c702ecb9c4c to your computer and use it in GitHub Desktop.
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