From d340dca940c6b95c5139fb93370a94c779048770 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 30 Jan 2021 05:39:16 -0800 Subject: [PATCH] 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 Reviewed-By: Zijian Liu Reviewed-By: Luigi Pinca --- doc/api/repl.md | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/doc/api/repl.md b/doc/api/repl.md index 77a735df2bf7eb..9ebe6481729575 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -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