github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/commands/catch.md (about) 1 # `catch` 2 3 > Handles the exception code raised by `try` or `trypipe` 4 5 ## Description 6 7 `catch` is designed to be used in conjunction with `try` and `trypipe` as it 8 handles the exceptions raised by the aforementioned. 9 10 ## Usage 11 12 ``` 13 [ try | trypipe ] { code-block } -> <stdout> 14 15 catch { code-block } -> <stdout> 16 17 !catch { code-block } -> <stdout> 18 ``` 19 20 ## Examples 21 22 ``` 23 try { 24 out "Hello, World!" -> grep: "non-existent string" 25 out "This command will be ignored" 26 } 27 28 catch { 29 out "An error was caught" 30 } 31 32 !catch { 33 out "No errors were raised" 34 } 35 ``` 36 37 ## Detail 38 39 `catch` can be used with a bang prefix to check for a lack of errors. 40 41 `catch` forwards on the STDIN and exit number of the calling function. 42 43 ## Synonyms 44 45 * `catch` 46 * `!catch` 47 48 49 ## See Also 50 51 * [Schedulers](../user-guide/schedulers.md): 52 Overview of the different schedulers (or 'run modes') in Murex 53 * [`if`](../commands/if.md): 54 Conditional statement to execute different blocks of code depending on the result of the condition 55 * [`runmode`](../commands/runmode.md): 56 Alter the scheduler's behaviour at higher scoping level 57 * [`switch`](../commands/switch.md): 58 Blocks of cascading conditionals 59 * [`try`](../commands/try.md): 60 Handles non-zero exits inside a block of code 61 * [`tryerr`](../commands/tryerr.md): 62 Handles errors inside a block of code 63 * [`trypipe`](../commands/trypipe.md): 64 Checks for non-zero exits of each function in a pipeline 65 * [`trypipeerr`](../commands/trypipeerr.md): 66 Checks state of each function in a pipeline and exits block on error 67 * [`unsafe`](../commands/unsafe.md): 68 Execute a block of code, always returning a zero exit number 69 70 <hr/> 71 72 This document was generated from [builtins/core/structs/try_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/structs/try_doc.yaml).