nodejs throw error what happens next code example
Example 1: node js throw error
FactoryController.prototype.create = function (callback) {
throw new Error('An error occurred');
try {
this.check(function (check_result) {
callback(check_result);
});
} catch (ex) {
throw new Error(ex.toString());
}
}
FactoryController.prototype.create = function (callback) {
try {
this.check(function (check_result) {
throw new Error('An error occurred');
});
} catch (ex) {
throw new Error(ex.toString());
}
}
Example 2: error handling in call back function in nodejs
fs.readFile('/foo.txt', function(err, data) {
console.log(data);
});