Skip to content

Commit 045d98f

Browse files
committed
doc: add process.addUncaughtExceptionCaptureCallback
1 parent feb02dd commit 045d98f

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

doc/api/process.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,42 @@ generate a core file.
736736

737737
This 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,
40384074
method with a non-`null` argument while another capture function is set will
40394075
throw 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
@@ -4571,6 +4607,7 @@ cases:
45714607
[`net.Socket`]: net.md#class-netsocket
45724608
[`os.constants.dlopen`]: os.md#dlopen-constants
45734609
[`postMessageToThread()`]: worker_threads.md#worker_threadspostmessagetothreadthreadid-value-transferlist-timeout
4610+
[`process.addUncaughtExceptionCaptureCallback()`]: #processadduncaughtexceptioncapturecallbackfn
45744611
[`process.argv`]: #processargv
45754612
[`process.config`]: #processconfig
45764613
[`process.execPath`]: #processexecpath

0 commit comments

Comments
 (0)