// BDE - (C) Copyright 1995 by Borland International // errval.c #include "snipit.h" //===================================================================== // Function: // ErrVal(); // // Description: // IDAPI functions return error codes to inform the calling // program if the function succeeded or failed. The return value // will be equal to DBIERR_NONE when the function was // successful. // This example shows how to get information about an error // when an IDAPI function returns a value other than DBIERR_NONE. //===================================================================== void ErrVal (void) { DBIResult rslt; // Value returned from IDAPI functions hDBIDb hDb; // Handle to the database DBIMSG dbi_status; // Error String DBIErrInfo ErrInfo; // Contains information about the error Screen("*** Getting Error Information ***\r\n"); BREAK_IN_DEBUGGER(); // Open a standard database (used to access Paradox and dBASE // tables), by using a NULL database type. Note that this will fail // because we have not initialized IDAPI. Screen(" Attempt to open the database..."); Screen(" Error Expected - Engine not initialized."); rslt = DbiOpenDatabase("", NULL, dbiREADWRITE, dbiOPENSHARED, NULL, 0, NULL, NULL, &hDb); if ((rslt != DBIERR_CANTFINDODAPI) && (rslt != DBIERR_NOTINITIALIZED)) { if (rslt != DBIERR_NONE) { // Note - make certain to call DbiGetErrorInfo() right after // the error as it will only give information about the most // recent error. DbiGetErrorInfo(TRUE, &ErrInfo); // Check to see if DbiGetErrorInfo is reporting information // on the same error that you have. (Done in case DbiGetErrorInfo // was not called immediately after the function which failed.) if (ErrInfo.iError == rslt) { Screen(" ERROR - Cat:Code = [%xh:%xh]" "\r\n %s", ErrCat(ErrInfo.iError), ErrCode(ErrInfo.iError), ErrInfo.szErrCode); // Need to check how much information was provided - // different errors return different amounts of information. if (strcmp(ErrInfo.szContext1, "")) { Screen(" %s", ErrInfo.szContext1); } if (strcmp(ErrInfo.szContext2, "")) { Screen(" %s", ErrInfo.szContext2); } if (strcmp(ErrInfo.szContext3, "")) { Screen(" %s", ErrInfo.szContext3); } if (strcmp(ErrInfo.szContext4, "")) { Screen(" %s", ErrInfo.szContext4); } } else { DbiGetErrorString(rslt, dbi_status); Screen(" ERROR - Cat:Code [%xh:%xh]" "\r\n %s", ErrCat(rslt), ErrCode(rslt), dbi_status); } } } else { Screen(" Engine not initialized."); } // Check if this is the expected error. if (rslt != DBIERR_NOTINITIALIZED) { Screen(" Unexpected Condition - terminating example"); } Screen("\r\n*** End of Example ***"); }