node js throw error
FactoryController.prototype.create = function (callback) { //The throw is working, and the exception is returned. throw new Error('An error occurred'); //outside callback 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) { //The throw is not working on this case to return the exception to the caller(parent) throw new Error('An error occurred'); //inside callback }); } catch (ex) { throw new Error(ex.toString()); } }
Source: stackoverflow.com
error handling in node js
app.get('/', function (req, res, next) { Promise.resolve().then(function () { throw new Error('BROKEN') }).catch(next) // Errors will be passed to Express. })
Source: expressjs.com
error handling in node.js
app.use(( err, req, res, next ) => { res.locals.error = err; if (err.status >= 100 && err.status < 600) res.status(err.status); else res.status(500); res.render('error'); });
node.js error handling
process.on('warning', veri => console.log(veri)) process.on('unhandledRejection', veri => console.log(veri)) process.on('uncaughtException', veri => console.log(veri))