Skip to content

Instantly share code, notes, and snippets.

@deepal
Last active October 14, 2019 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deepal/e6d21ab827d5131c7e3b to your computer and use it in GitHub Desktop.
Save deepal/e6d21ab827d5131c7e3b to your computer and use it in GitHub Desktop.
nodesec-error-handling
//snippet1 : Following is not a proper error handling when myAsyncFunction() is an asynchronous function
try {
myAsyncFunction(somedata, function(err, response){
//this is asynchronous function callback
});
}
catch(err){
console.log('I will never catch the error');
}
//snippet2 : Following is a proper error handling when mySyncFunction() is synchronous
try {
var val = mySyncFunction(somedata);
/* do something with val */
}
catch(err){
console.log('Yes. I caught the error');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment