Skip to content

Commit 390d38b

Browse files
authored
Add try on external commands mention (#1891)
1 parent 973f881 commit 390d38b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

book/control_flow.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,24 @@ try { 1 / 0 } catch { 'An error happened!' } | $in ++ ' And now I am resuming.'
328328

329329
It will not execute the `catch` block if an error did not occur.
330330

331+
`try` also works for external commands:
332+
333+
```nu
334+
try { ^nonexisting }; print 'a'
335+
# => a
336+
337+
^nonexisting; print 'a'
338+
# => Error: nu::shell::external_command
339+
# =>
340+
# => × External command failed
341+
# => ╭─[entry #3:1:2]
342+
# => 1 │ ^nonexisting; print 'a'
343+
# => · ─────┬─────
344+
# => · ╰── Command `nonexisting` not found
345+
# => ╰────
346+
# => help: `nonexisting` is neither a Nushell built-in or a known external command
347+
```
348+
331349
## Other
332350

333351
### `return`

0 commit comments

Comments
 (0)