node js catch exception code example
Example 1: node js try catch
try {
nonExistentFunction();
} catch (error) {
console.error(error);
// expected output: ReferenceError: nonExistentFunction is not defined
// Note - error messages will vary depending on browser
}
Example 2: node js catch any errors
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
});