# RXS_Catch()

This subprocedure can be used to catch an error thrown by [RXS_Throw()](https://isupport.katointegrations.com/rxs/3.2/rxs_throw.md) or via other methods. The error information is retrieved into a RXS_CatchThrowErrorDS_t data structure.

Typical usage involves this subprocedure being called inside the ON-ERROR section of a MONITOR group.

## Subprocedure Prototype

### IBM i 6.1+

```rpgle
      // Returns RXS_CatchThrowErrorDS_t data structure containing the error
      //   information that was previously thrown.
     D RXS_Catch...
     D                 PR                  Extproc('RXS_Catch')
     D                                     Likeds(RXS_CatchThrowErrorDS_t)
```


## Example Code

### IBM i 6.1+

#### Example 1: Catch Error
```rpgle
      *--------------------------------------------------------------
      * This example demonstrates calling RXS_Catch() and assigning the return
      *  value to a RXS_CatchThrowErrorDS_t datastructure.
      *--------------------------------------------------------------
     H DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*NEW)

      /COPY QRPGLECPY,RXSCB

     D ErrorDS         DS                  LikeDS(RXS_CatchThrowErrorDS_t)
     D                                     Inz(*LikeDS)

     D NumA            S             10I 0
     D NumB            S             10I 0
     D Result          S             10I 0
      /FREE
       monitor;
         // To ensure we trigger an error, we're going to divide by 0.
         NumA = 5;
         NumB = 0;
         Result = NumA / NumB;
       on-error;
         // Note that you don't have to use RXS_ResetDS to initialize ErrorDS before
         //  using it - this is one of the few RXS data structures where
         //  this is safe and correct.
         ErrorDS = RXS_Catch();

         // At this point ErrorDS should contain the error information for an
         //  MCH1211 "divide by zero" error.
       endmon;

       return;
      /END-FREE
```

## Data Structures

### RXS_CatchThrowErrorDS_t

```rpgle
     D RXS_CatchThrowErrorDS_t...
     D                 DS                  Qualified Template Inz

      // The message ID that was received.
     D   MessageId                    7A

      // The message file used to store the message ID.
     D   MessageFile                 20A

      // The message data to be merged with the text of the message ID.
     D   MessageData               1024A   Varying

     D   DataStructureType...
     D                                5I 0 Inz(RXS_DS_TYPE_CATCHTHROWERROR)

      // The type of message that was sent.
      // Valid values: RXS_MESSAGE_TYPE_DIAG, RXS_MESSAGE_TYPE_COMP,
      //   RXS_MESSAGE_TYPE_INFO, RXS_MESSAGE_TYPE_INQ, RXS_MESSAGE_TYPE_RQS,
      //   RXS_MESSAGE_TYPE_NOTIFY, RXS_MESSAGE_TYPE_ESCAPE,
      //   RXS_MESSAGE_TYPE_STATUS
     D   MessageType                  5I 0

      // The full message text that combines the value of the message ID's text
      //   and the merged message data.
     D   MessageText               4096A   Varying

      // Not used. Used by RXS_Throw() only.
     D   ThrowToCaller...
     D                                 N   Inz(RXS_NO)
```

