@@ -736,6 +736,42 @@ generate a core file.
736736
737737This feature is not available in [ ` Worker ` ] [ ] threads.
738738
739+ ## ` process.addUncaughtExceptionCaptureCallback(fn) `
740+
741+ <!-- YAML
742+ added: REPLACEME
743+ -->
744+
745+ * ` fn ` {Function}
746+
747+ The ` process.addUncaughtExceptionCaptureCallback() ` function adds a callback
748+ that will be invoked when an uncaught exception occurs, receiving the exception
749+ value as its first argument.
750+
751+ Unlike [ ` process.setUncaughtExceptionCaptureCallback() ` ] [ ] , this function allows
752+ multiple callbacks to be registered and does not conflict with the
753+ [ ` domain ` ] [ ] module. Callbacks are called in reverse order of registration
754+ (most recent first). If a callback returns ` true ` , subsequent callbacks
755+ and the default uncaught exception handling are skipped.
756+
757+ ``` mjs
758+ import process from ' node:process' ;
759+
760+ process .addUncaughtExceptionCaptureCallback ((err ) => {
761+ console .error (' Caught exception:' , err .message );
762+ return true ; // Indicates exception was handled
763+ });
764+ ```
765+
766+ ``` cjs
767+ const process = require (' node:process' );
768+
769+ process .addUncaughtExceptionCaptureCallback ((err ) => {
770+ console .error (' Caught exception:' , err .message );
771+ return true ; // Indicates exception was handled
772+ });
773+ ```
774+
739775## ` process.allowedNodeEnvironmentFlags `
740776
741777<!-- YAML
@@ -4038,8 +4074,8 @@ To unset the capture function,
40384074method with a non-` null ` argument while another capture function is set will
40394075throw an error.
40404076
4041- Using this function is mutually exclusive with using the deprecated
4042- [` domain ` ][] built-in module .
4077+ To register multiple callbacks that can coexist, use
4078+ [` process . addUncaughtExceptionCaptureCallback () ` ][] instead .
40434079
40444080## ` process .sourceMapsEnabled `
40454081
@@ -4545,6 +4581,7 @@ cases:
45454581[` net .Socket ` ]: net.md#class-netsocket
45464582[` os .constants .dlopen ` ]: os.md#dlopen-constants
45474583[` postMessageToThread ()` ]: worker_threads.md#worker_threadspostmessagetothreadthreadid-value-transferlist-timeout
4584+ [` process .addUncaughtExceptionCaptureCallback ()` ]: #processadduncaughtexceptioncapturecallbackfn
45484585[` process .argv ` ]: #processargv
45494586[` process .config ` ]: #processconfig
45504587[` process .execPath ` ]: #processexecpath
0 commit comments