“Penanganan kesalahan di Node JS” Kode Jawaban

kesalahan lemparan node js

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());
    }
}
Helpless Hoopoe

Penanganan kesalahan di Node JS

app.get('/', function (req, res, next) {
  Promise.resolve().then(function () {
    throw new Error('BROKEN')
  }).catch(next) // Errors will be passed to Express.
})
Beautiful Badger

Penanganan kesalahan di 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');
});
Super Sloth

penanganan kesalahan node.js

process.on('warning', veri => console.log(veri))
process.on('unhandledRejection', veri => console.log(veri))
process.on('uncaughtException', veri => console.log(veri))
Pudochu

Jawaban yang mirip dengan “Penanganan kesalahan di Node JS”

Pertanyaan yang mirip dengan “Penanganan kesalahan di Node JS”

Lebih banyak jawaban terkait untuk “Penanganan kesalahan di Node JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya