github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/commands/try.md (about) 1 # `try` 2 3 > Handles non-zero exits inside a block of code 4 5 ## Description 6 7 `try` forces a different execution behavior where a failed process at the end 8 of a pipeline will cause the block to terminate regardless of any functions that 9 might follow. 10 11 It's usage is similar to try blocks in other languages (eg Java) but a closer 12 functional example would be `set -e` in Bash. 13 14 To maintain concurrency within the pipeline, `try` will only check the last 15 function in any given pipeline (ie series of functions joined via `|`, `->`, or 16 similar operators). If you need the entire pipeline checked then use `trypipe`. 17 18 ## Usage 19 20 ``` 21 try { code-block } -> <stdout> 22 23 <stdin> -> try { -> code-block } -> <stdout> 24 ``` 25 26 ## Examples 27 28 ``` 29 try { 30 out "Hello, World!" -> grep: "non-existent string" 31 out "This command will be ignored" 32 } 33 ``` 34 35 ## Detail 36 37 A failure is determined by: 38 39 * Any process that returns a non-zero exit number 40 41 You can see which run mode your functions are executing under via the `fid-list` 42 command. 43 44 ## See Also 45 46 * [Schedulers](../user-guide/schedulers.md): 47 Overview of the different schedulers (or 'run modes') in Murex 48 * [`catch`](../commands/catch.md): 49 Handles the exception code raised by `try` or `trypipe` 50 * [`fid-list`](../commands/fid-list.md): 51 Lists all running functions within the current Murex session 52 * [`if`](../commands/if.md): 53 Conditional statement to execute different blocks of code depending on the result of the condition 54 * [`runmode`](../commands/runmode.md): 55 Alter the scheduler's behaviour at higher scoping level 56 * [`switch`](../commands/switch.md): 57 Blocks of cascading conditionals 58 * [`tryerr`](../commands/tryerr.md): 59 Handles errors inside a block of code 60 * [`trypipe`](../commands/trypipe.md): 61 Checks for non-zero exits of each function in a pipeline 62 * [`trypipeerr`](../commands/trypipeerr.md): 63 Checks state of each function in a pipeline and exits block on error 64 * [`unsafe`](../commands/unsafe.md): 65 Execute a block of code, always returning a zero exit number 66 67 <hr/> 68 69 This document was generated from [builtins/core/structs/try_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/structs/try_doc.yaml).