github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/commands/tryerr.md (about)

     1  # `tryerr`
     2  
     3  > Handles errors inside a block of code
     4  
     5  ## Description
     6  
     7  `tryerr` 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, `tryerr` 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  tryerr { code-block } -> <stdout>
    22  
    23  <stdin> -> tryerr { -> code-block } -> <stdout>
    24  ```
    25  
    26  ## Examples
    27  
    28  ```
    29  tryerr {
    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  * Any process that returns more output via STDERR than it does via STDOUT
    41  
    42  You can see which run mode your functions are executing under via the `fid-list`
    43  command.
    44  
    45  ## See Also
    46  
    47  * [Schedulers](../user-guide/schedulers.md):
    48    Overview of the different schedulers (or 'run modes') in Murex
    49  * [`catch`](../commands/catch.md):
    50    Handles the exception code raised by `try` or `trypipe`
    51  * [`fid-list`](../commands/fid-list.md):
    52    Lists all running functions within the current Murex session
    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  * [`trypipe`](../commands/trypipe.md):
    62    Checks for non-zero exits of each function in a pipeline
    63  * [`trypipeerr`](../commands/trypipeerr.md):
    64    Checks state of each function in a pipeline and exits block on error
    65  * [`unsafe`](../commands/unsafe.md):
    66    Execute a block of code, always returning a zero exit number
    67  
    68  <hr/>
    69  
    70  This document was generated from [builtins/core/structs/tryerr_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/structs/tryerr_doc.yaml).