From e30e035dcdbe3a4d0af62211496be6ca100a7204 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 | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/doc/api/repl.md b/doc/api/repl.md index 10536aeb0e..bf5ee1efef 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -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