mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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: https://github.com/nodejs/node/pull/37142 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
@@ -163,31 +163,22 @@ 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`][].
|
||||
another Node.js program results in [`ERR_INVALID_REPL_INPUT`][].
|
||||
|
||||
```js
|
||||
const r = repl.start();
|
||||
|
||||
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
|
||||
|
||||
r.close();
|
||||
```
|
||||
|
||||
* 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'));
|
||||
|
||||
throw new Error('foobar');
|
||||
// Uncaught
|
||||
```
|
||||
|
||||
When used in another application:
|
||||
|
||||
```js
|
||||
process.on('uncaughtException', () => console.log('Uncaught'));
|
||||
// TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException`
|
||||
// cannot be used in the REPL
|
||||
|
||||
throw new Error('foobar');
|
||||
// Thrown:
|
||||
// Error: foobar
|
||||
```
|
||||
|
||||
#### Assignment of the `_` (underscore) variable
|
||||
<!-- YAML
|
||||
changes:
|
||||
|
||||
Reference in New Issue
Block a user