全局未捕获异常
【Global uncaught exceptions】
REPL 使用 domain 模块来捕获该 REPL 会话中所有未捕获的异常。
【The REPL uses the domain module to catch all uncaught exceptions for that
REPL session.】
在 REPL 中使用 domain 模块会产生以下副作用:
【This use of the domain module in the REPL has these side effects:】
-
未捕获的异常只会在独立的 REPL 中触发
'uncaughtException'事件。在另一个 Node.js 程序中的 REPL 中为该事件添加监听器会导致ERR_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(); -
尝试使用
process.setUncaughtExceptionCaptureCallback()会抛出ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE错误。