Last active
October 14, 2019 20:59
-
-
Save deepal/e6d21ab827d5131c7e3b to your computer and use it in GitHub Desktop.
nodesec-error-handling
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
//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