express throw error 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: express error handling
app.use(function (err, req, res, next) {
console.error(err.stack)
res.status(500).send('Something broke!')
})
Example 3: express generator error handling
app.get('/', function (req, res) {
throw new Error('BROKEN')
})