Skip to content

Commit

Permalink
doc: clarify repl exception conditions
Browse files Browse the repository at this point in the history
The sample code demonstrating ERR_INVALID_REPL_INPUT is confusing, I
think. This simplifies and clarifies it a bit, I hope.

PR-URL: #37142
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Trott authored and targos committed May 1, 2021
1 parent 26ec20a commit d340dca
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions doc/api/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,30 +163,21 @@ This use of the [`domain`][] module in the REPL has these side effects:

* Uncaught exceptions only emit the [`'uncaughtException'`][] event in the
standalone REPL. Adding a listener for this event in a REPL within
another Node.js program throws [`ERR_INVALID_REPL_INPUT`][].
* Trying to use [`process.setUncaughtExceptionCaptureCallback()`][] throws
an [`ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE`][] error.

As standalone program:

```js
process.on('uncaughtException', () => console.log('Uncaught'));
another Node.js program results in [`ERR_INVALID_REPL_INPUT`][].

throw new Error('foobar');
// Uncaught
```
```js
const r = repl.start();

When used in another application:
r.write('process.on("uncaughtException", () => console.log("Foobar"));\n');
// Output stream includes:
// TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException`
// cannot be used in the REPL

```js
process.on('uncaughtException', () => console.log('Uncaught'));
// TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException`
// cannot be used in the REPL
r.close();
```

throw new Error('foobar');
// Thrown:
// Error: foobar
```
* Trying to use [`process.setUncaughtExceptionCaptureCallback()`][] throws
an [`ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE`][] error.

#### Assignment of the `_` (underscore) variable
<!-- YAML
Expand Down

0 comments on commit d340dca

Please sign in to comment.