Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

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 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 zero

Try to run a division by zero and report the message

> try { 1 / 0 } catch { |err| $err.msg }

Notes

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