Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Datatypes [Table of Contents] Lists

Sybase dbQueue Reference Guide

[-] Chapter 1: Using the dbQueue Objects Library
[-] Error Processing

Error Processing

All methods in the dbQueue objects library return a status value; the only exceptions are attribute accessor functions and certain helper functions. If a call is successful, the status value is always DBQ_SUCCEED. If a call fails, the status value contains an error code that indicates the source of the error.

The following code sample shows how to check for a particular error code emanating from a domain installation:

DBQ_INT status = dom->Install();
switch (status) 
{
    case DBQ_SUCCEED:
        printf("Catalog installation ok\n"); break;
    case DBQ_E_DOM_LOGIN_FAIL:
        printf("Login failure!\n"); break;
    default:
        printf("Unknown error!\n");
}

In the event of an error, the dbQueue objects library also generates one or more detailed error messages in the form of DbqErr instances. Applications can retrieve these error messages from the DbqErr instance using the FetchError() method. The following code sample shows how to gather and print error messages from DbqErr instances after a failed operation for adding an application database.

status = appdb->Add(); 
if (status != DBQ_SUCCEED)
{
    DbqErr* error;
    while ((error = appdb->FetchError()) != DBQ_NULL)
    {
        printf("Error #: %d\n", 
                error->GetNumber());
        printf("Category: %d\n", 
                error->GetCategory()); 
        printf("Text: %s\n", error->GetMessage());
        delete error;
    }
}

The error processing loop shown is a more general form of error processing using individual error codes. This code works regardless of the type of errors that are generated. It is a useful coding model for error administration.

When there are multiple errors, a list of errors is generated. The first error returned by FetchError() is guaranteed to match the status value returned by the failed method call. The list of errors is cleared between calls. Therefore, the error messages must be examined immediately after the failure.

The DbqEnv::NewEnv() method, which initializes the dbQueue objects library, returns only an error code. Error message handling is supported only on individual object instances.


Datatypes [Table of Contents] Lists