Skip to content

Commit e712650

Browse files
Trotttargos
authored andcommitted
doc: clarify repl exception conditions
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>
1 parent e55d3d0 commit e712650

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

doc/api/repl.md

+11-20
Original file line numberDiff line numberDiff line change
@@ -163,30 +163,21 @@ This use of the [`domain`][] module in the REPL has these side effects:
163163

164164
* Uncaught exceptions only emit the [`'uncaughtException'`][] event in the
165165
standalone REPL. Adding a listener for this event in a REPL within
166-
another Node.js program throws [`ERR_INVALID_REPL_INPUT`][].
167-
* Trying to use [`process.setUncaughtExceptionCaptureCallback()`][] throws
168-
an [`ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE`][] error.
169-
170-
As standalone program:
171-
172-
```js
173-
process.on('uncaughtException', () => console.log('Uncaught'));
166+
another Node.js program results in [`ERR_INVALID_REPL_INPUT`][].
174167

175-
throw new Error('foobar');
176-
// Uncaught
177-
```
168+
```js
169+
const r = repl.start();
178170

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

181-
```js
182-
process.on('uncaughtException', () => console.log('Uncaught'));
183-
// TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException`
184-
// cannot be used in the REPL
176+
r.close();
177+
```
185178

186-
throw new Error('foobar');
187-
// Thrown:
188-
// Error: foobar
189-
```
179+
* Trying to use [`process.setUncaughtExceptionCaptureCallback()`][] throws
180+
an [`ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE`][] error.
190181

191182
#### Assignment of the `_` (underscore) variable
192183
<!-- YAML

0 commit comments

Comments
 (0)