diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-02-21 21:50:20 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-03-04 22:01:57 +0000 |
commit | a8b5192fefe54b140ae923e749104b49c5d3be49 (patch) | |
tree | 1cc9208c625d314a71ed53581386735bf2378a52 /doc/api/repl.md | |
parent | 648d668fcc29dafeb99f90d89087b682457f96b3 (diff) | |
download | android-node-v8-a8b5192fefe54b140ae923e749104b49c5d3be49.tar.gz android-node-v8-a8b5192fefe54b140ae923e749104b49c5d3be49.tar.bz2 android-node-v8-a8b5192fefe54b140ae923e749104b49c5d3be49.zip |
repl: make last error available as `_error`
This is pretty useful when trying to inspect the last
error caught by a REPL, and is made to be analogous to `_`,
which contains the last successful completion value.
PR-URL: https://github.com/nodejs/node/pull/18919
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Diffstat (limited to 'doc/api/repl.md')
-rw-r--r-- | doc/api/repl.md | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/doc/api/repl.md b/doc/api/repl.md index 873e7449f5..c868106f2f 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -142,6 +142,12 @@ global or scoped variable, the input `fs` will be evaluated on-demand as ``` #### Assignment of the `_` (underscore) variable +<!-- YAML +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/18919 + description: Added `_error` support. +--> The default evaluator will, by default, assign the result of the most recently evaluated expression to the special variable `_` (underscore). @@ -162,6 +168,17 @@ Expression assignment to _ now disabled. 4 ``` +Similarly, `_error` will refer to the last seen error, if there was any. +Explicitly setting `_error` to a value will disable this behavior. + +<!-- eslint-skip --> +```js +> throw new Error('foo'); +Error: foo +> _error.message +'foo' +``` + ### Custom Evaluation Functions When a new `repl.REPLServer` is created, a custom evaluation function may be |