try for core
Try to run a block, if it fails optionally run a catch closure.
Signature
> try {flags} (try_block) (catch) (finally)
Parameters
try_block: Block to run.catch: Closure to run if try block fails.finally: Closure to run anyway.
Input/output types:
| input | output |
|---|---|
| any | any |
Examples
Try to run a division by zero.
> try { 1 / 0 }Try to run a division by zero and return a string instead.
> try { 1 / 0 } catch { 'divided by zero' }
divided by zeroTry to run a division by zero and report the message.
> try { 1 / 0 } catch { |err| $err.msg }Try to run a division by zero, report the message, and run finally
> try { 1 / 0 } catch { |err| print $err.msg } finally { 'clean' }Notes
This command is a parser keyword. For details, check: https://www.nushell.sh/book/thinking_in_nu.html