Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,44 @@ generate a core file.

This feature is not available in [`Worker`][] threads.

## `process.addUncaughtExceptionCaptureCallback(fn)`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we land it as experimental first?


<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental

* `fn` {Function}

The `process.addUncaughtExceptionCaptureCallback()` function adds a callback
that will be invoked when an uncaught exception occurs, receiving the exception
value as its first argument.

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.

```mjs
import process from 'node:process';

process.addUncaughtExceptionCaptureCallback((err) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it be available on global process?

console.error('Caught exception:', err.message);
return true; // Indicates exception was handled
});
```

```cjs
const process = require('node:process');

process.addUncaughtExceptionCaptureCallback((err) => {
console.error('Caught exception:', err.message);
return true; // Indicates exception was handled
});
```

## `process.allowedNodeEnvironmentFlags`

<!-- YAML
Expand Down Expand Up @@ -4021,6 +4059,11 @@ This implies calling `module.setSourceMapsSupport()` with an option

<!-- YAML
added: v9.3.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/61227
description: Use `process.addUncaughtExceptionCaptureCallback()` to
register multiple callbacks.
-->

* `fn` {Function|null}
Expand All @@ -4040,8 +4083,8 @@ To unset the capture function,
method with a non-`null` argument while another capture function is set will
throw an error.

Using this function is mutually exclusive with using the deprecated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should add this to changes: at the top of this function documentation