最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why uncaughtException handler not working globally? - Stack Overflow

programmeradmin3浏览0评论

I'm developing a Express + PostgreSQL app and I want to implement a global error handler system. Now I want to caught all uncaught exceptions from my entire project. Server is running with nodemon.

A code like this console.log(x) should give a custom error that I created because x is not defined;

I'm putting process.on('uncaughtException', () => {}) in my server.js file, located in root directory and inserting error with console.log(x) in app.js that is also in root directory folder.

Here is my server.js code:

import './src/config/dotenv.js';
import app from './app.js';

process.on('uncaughtException', (err) => {
  console.log(err.name, err.message);
  console.log('UNCAUGHT EXCEPTION! 
发布评论

评论列表(0)

  1. 暂无评论