Examples: Receiving error conditions

These examples illustrate receiving error conditions

Example: Receiving error conditions as exceptions

This example shows an application that receives error conditions as exceptions. It allocates an error code parameter that is a minimum of 4 bytes long to hold the bytes provided field. The only field used is the bytes-provided INPUT field, which the application sets to zero to request exceptions. The error code parameter contains the following:

Field INPUT OUTPUT
Bytes provided 0 0

Example: Receiving the error code without the exception data

This application example attempts to create an alert for message ID USR1234 in message file USRMSG in library QGPL. It receives the error condition in the error code parameter but does not receive any exception data. To do this, it allocates an error code parameter that is a minimum of 16 bytes long--for the bytes provided, bytes available, exception ID, and reserved fields. It sets the bytes-provided field of the error code parameter to 16.

When the application calls the Generate Alert (QALGENA) API, the alert table USRMSG is not found, and QALGENA returns exception CPF7B03. The error code parameter contains the data shown in the following table. In this example, 16 bytes are provided for data, but 36 are available. Twenty more bytes of data could be returned if the bytes-provided field were set to reflect a larger error code parameter.

Field INPUT OUTPUT
Bytes provided 16 16
Bytes available Ignored 36
Exception ID Ignored CPF7B03
Reserved Ignored 0

Example: Receiving the error code with the exception data

This application example attempts to create an alert for message ID USR1234 in message file USRMSG in library QGPL. It receives the error condition in the error code parameter and receives exception data as well. To do this, it allocates an error code parameter that is 116 bytes long--16 bytes for the bytes provided, bytes available, exception ID, and reserved fields, and 100 bytes for the exception data for the exception. (In some cases, the exception data might be a variable-length directory or file name, so this might not be large enough to hold all of the data; whatever fits is returned in the error code parameter.) Finally, it sets the bytes-provided field to 116.

When the application calls the Generate Alert (QALGENA) API, the alert table USRMSG is not found, and QALGENA returns exception CPF7B03. The error code parameter contains the following:

Field INPUT OUTPUT
Bytes provided 116 116
Bytes available Ignored 36
Exception ID Ignored CPF7B03
Reserved Ignored 0
Exception data Ignored USRMSG QGPL