Informix GLS exceptions

Many of the functions return a unique value if they encounter an error. To further identify the cause of the error, you can use the ifx_gl_lc_errno() function to obtain the value of the error number.

The ifx_gl_lc_errno() function returns the error number as an int value. library functions can use ifx_gl_lc_errno() to obtain more information about an error that has occurred. The functions set the error number only if an error occurs unless a particular function is documented otherwise.

Because any library function can set the error number, you must call ifx_gl_lc_errno() immediately after the function in which the error occurred to inspect the relevant value of the error number.

For example, the ifx_gl_mbslen() function returns a value of -1 when it encounters an error. The following code fragment shows how to use the ifx_gl_lc_errno() function to obtain the error number:
if ( ifx_gl_mbslen(mbs, n) == -1 )
    switch ( ifx_gl_lc_errno() )
    ...
An application can also ignore the return value of the function and check the ifx_gl_lc_errno() function if the application sets ifx_gl_lc_errno() to 0 before it calls the function.
ifx_gl_lc_errno() = 0;
(void) ifx_gl_mbslen(mbs, n);
if ( ifx_gl_lc_errno() != 0 )
    switch ( ifx_gl_lc_errno() )
    ...
If the library function does not return a unique value to indicate that an error has occurred, you must use the preceding technique to obtain the error number. For example, the following code fragment tests whether the ifx_gl_ismupper() function has detected an invalid multibyte character:
ifx_gl_lc_errno() = 0;
value = ifx_gl_ismupper(mb, IFX_GL_NO_LIMIT);
if ( ifx_gl_lc_errno() != 0 )
    switch ( ifx_gl_lc_errno() )
    ...
You can set ifx_gl_lc_errno() to 0 and check it after a function call only if the current processing locale was initialized correctly with ifx_gl_init(). For example, the following code fragment of a client application results in a memory fault because the current processing locale is uninitialized:
int wrong_func()
{
    ifx_gl_lc_errno() = 0;    /* A memory fault will occur here. */
    (void) ifx_gl_init();
    if ( ifx_gl_lc_errno() != 0 )
        switch ( ifx_gl_lc_errno() )
        ...

In the preceding code fragment, the ifx_gl_lc_errno() function can write or read the error number only after a call to the ifx_gl_init() function has correctly initialized the current processing locale.

The following code fragment of a client application executes successfully because it correctly initializes the server-processing locale:
int right_func()
{
    (void) ifx_gl_init();
    ifx_gl_lc_errno() = 0;
    if ( ifx_gl_lc_errno() != 0 )
        switch ( ifx_gl_lc_errno() )
        ...

For multithreaded ESQL/C applications, the error-number value is stored as a field in the thread control block. Therefore, multithreaded ESQL/C applications can use the error number.