全局的未捕获异常
REPL 使用 domain
模块来捕获该 REPL 会话的所有未捕获的异常。
在 REPL 中使用 domain
模块有这些副作用:
-
未捕获的异常仅在独立 REPL 中触发
'uncaughtException'
事件。 在另一个 Node.js 程序的 REPL 中为此事件添加监听器会导致ERR_INVALID_REPL_INPUT
。const r = repl.start(); r.write('process.on("uncaughtException", () => console.log("Foobar"));\n'); // 输出流包括: // TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException` // cannot be used in the REPL r.close();
-
尝试使用
process.setUncaughtExceptionCaptureCallback()
会抛出ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE
错误。
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:
-
Uncaught exceptions only emit the
'uncaughtException'
event in the standalone REPL. Adding a listener for this event in a REPL within another Node.js program results inERR_INVALID_REPL_INPUT
.const r = repl.start(); r.write('process.on("uncaughtException", () => console.log("Foobar"));\n'); // Output stream includes: // TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException` // cannot be used in the REPL r.close();
-
Trying to use
process.setUncaughtExceptionCaptureCallback()
throws anERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE
error.