全局的未捕获异常


REPL 使用 domain 模块来捕获该 REPL 会话的所有未捕获的异常。

在 REPL 中使用 domain 模块有这些副作用:

process.on('uncaughtException', () => console.log('Uncaught'));

throw new Error('foobar');
// Uncaught
process.on('uncaughtException', () => console.log('Uncaught'));
// TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException`
// 

throw new Error('foobar');
// 
// 

The REPL uses the domain module to catch all uncaught exceptions for that REPL session.

This use of the domain module in the REPL has these side effects:

As standalone program:

process.on('uncaughtException', () => console.log('Uncaught'));

throw new Error('foobar');
// Uncaught

When used in another application:

process.on('uncaughtException', () => console.log('Uncaught'));
// TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException`
// cannot be used in the REPL

throw new Error('foobar');
// Thrown:
// Error: foobar