try for core

Try to run a block, if it fails optionally run a catch closure.

Signature

> try {flags} (try_block) (catch_closure)

Parameters

  • try_block: Block to run.
  • catch_closure: Closure to run if try block fails.

Input/output types:

inputoutput
anyany

Examples

Try to run a missing command

> try { asdfasdf }

Try to run a missing command

> try { asdfasdf } catch { 'missing' }
missing

Try to run a missing command and report the message

> try { asdfasdf } catch { |err| $err.msg }

Notes

This command is a parser keyword. For details, check: https://www.nushell.sh/book/thinking_in_nu.html