# RXS_Throw()

This subprocedure can be used to throw an error. The error information is populated into a data structure which is then passed to RXS_Throw. The error can be caught by [RXS_Catch()](https://isupport.katointegrations.com/rxs/3.5/rxs_catch.md).

## Subprocedure Prototype

```rpgle
     D RXS_Throw...
     D                 PR                  Extproc('RXS_Throw') Opdesc

      // The RXS_CatchThrowErrorDS_t data structure that contains the error
      //   information to be thrown.
     D  pDS                                Likeds(RXS_CatchThrowErrorDS_t)
     D                                     Options(*Varsize)
```


## Example Code

### Ex. 1
```rpgle
**FREE
// This example code demonstrates throwing a diagnostic error by assigning
//  values to a RXS_CatchThrowErrorDS_t datastructure and throwing the error
//  to the calling program.

Ctl-Opt ActGrp(*New) BndDir('RXSBND');

/COPY QRPGLECPY,RXSCB

Dcl-Ds ErrorDS LikeDS(RXS_CatchThrowErrorDS_t);

// Send a diagnostic error message

RXS_ResetDS( ErrorDS : RXS_DS_TYPE_CATCHTHROWERROR );
ErrorDS.MessageId = 'CPF9898';
ErrorDS.MessageFile = 'QCPFMSG';
ErrorDS.MessageData = 'This is a *DIAG error being thrown';
ErrorDS.MessageType = RXS_MESSAGE_TYPE_DIAG;
RXS_Throw( ErrorDS );

return;
```

## Data Structures

### RXS_CatchThrowErrorDS_t

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

      // The message ID for the message you wish to send.
     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 specified message
     D   MessageData               1024A   Varying

      // Internal use only
     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

      // Set to RXS_YES when you want the error sent to the program that called
      //   the program which is throwing the error. By default, the program
      //   throwing the error will be the target of the error.
      // Valid values: RXS_YES, RXS_NO
      // Default: RXS_NO
     D   ThrowToCaller...
     D                                 N   Inz(RXS_NO)
```

