process.addUncaughtExceptionCaptureCallback(fn)
fn<Function>
process.addUncaughtExceptionCaptureCallback() 函数添加一个回调函数,当发生未捕获的异常时会调用该回调函数,并将异常值作为其第一个参数传入。
🌐 The process.addUncaughtExceptionCaptureCallback() function adds a callback
that will be invoked when an uncaught exception occurs, receiving the exception
value as its first argument.
与 process.setUncaughtExceptionCaptureCallback() 不同,此功能允许注册多个回调,并且不会与 domain 模块冲突。回调按注册的相反顺序调用(最近注册的优先)。如果回调返回 true,则后续回调和默认的未捕获异常处理将被跳过。
🌐 Unlike process.setUncaughtExceptionCaptureCallback(), this function allows
multiple callbacks to be registered and does not conflict with the
domain module. Callbacks are called in reverse order of registration
(most recent first). If a callback returns true, subsequent callbacks
and the default uncaught exception handling are skipped.
import process from 'node:process';
process.addUncaughtExceptionCaptureCallback((err) => {
console.error('Caught exception:', err.message);
return true; // Indicates exception was handled
});const process = require('node:process');
process.addUncaughtExceptionCaptureCallback((err) => {
console.error('Caught exception:', err.message);
return true; // Indicates exception was handled
});