process.setUncaughtExceptionCaptureCallback(fn)
fn<Function> | <null>
process.setUncaughtExceptionCaptureCallback() 函数设置一个函数,当发生未捕获的异常时将调用该函数,该函数的第一个参数将接收异常本身。
【The process.setUncaughtExceptionCaptureCallback() function sets a function
that will be invoked when an uncaught exception occurs, which will receive the
exception value itself as its first argument.】
如果设置了这样的功能,将不会触发 'uncaughtException' 事件。如果通过命令行传递了 --abort-on-uncaught-exception 或通过 v8.setFlagsFromString() 设置,该进程也不会中止。在异常发生时配置的操作,例如报告生成,也会受到影响
【If such a function is set, the 'uncaughtException' event will
not be emitted. If --abort-on-uncaught-exception was passed from the
command line or set through v8.setFlagsFromString(), the process will
not abort. Actions configured to take place on exceptions such as report
generations will be affected too】
要取消捕获功能,可以使用 process.setUncaughtExceptionCaptureCallback(null)。在已经设置了其他捕获函数的情况下,如果调用此方法并传入非 null 参数,将会抛出错误。
【To unset the capture function,
process.setUncaughtExceptionCaptureCallback(null) may be used. Calling this
method with a non-null argument while another capture function is set will
throw an error.】
使用此功能与使用已弃用的 domain 内置模块是互斥的。
【Using this function is mutually exclusive with using the deprecated
domain built-in module.】