Jump to content

wpclsQueryError

From EDM2
Revision as of 21:28, 25 May 2025 by Martini (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This class method queries the current error code held within a class object.

Syntax

_wpclsQueryError(somSelf)

Parameters

somSelf (M_WPObject *) - input
Pointer to the WPObject class object.
ulErrorId (ULONG) - returns
ID of the last error. Last error that occurred when using this class object.

Returns

ulErrorId (ULONG) - returns
ID of the last error. Last error that occurred when using this class object.

Remarks

When an error occurs within a class method and that method subsequently fails, the calling procedure can retrieve the error code for that failed method call by using the wpclsQueryError method. Note that the error code is always that of the last method that failed. A successful method does not modify the error code held within a class object. This method is analogous to the WinGetErrorInfo and the WinGetLastError function calls that are used by Presentation Manager applications to diagnose the reason for the previous failing call to a Presentation Manager function call.

The system-provided class methods will return error codes as defined in the header file PMERR.H. For example, the wpclsQueryObject method will normally log an error of WPERR_OBJECT_NOT_FOUND if it is unable to return an object pointer.

How to Override

Never override this class method.

Usage

This method should be called immediately after a class method has failed in order to diagnose why the failure occurred.

Example Code

Declaration:

#define INCL_WINWORKPLACE
#include <os2.h>

M_WPObject     *somSelf;    /*  Pointer to the WPObject class object. */
ULONG           ulErrorId;  /*  ID of the last error. */

ulErrorId = _wpclsQueryError(somSelf);

This example finds all occurrences of an object type in a folder.

VOID  clsFindEverybody(SOMAny *self)
{
   BOOL      rc;                 /* Return from methods */
   HFIND     hFind       = 0;    /* Handle for repeated finds */
   CLASS     Class[2];           /* List of classes to look for */
   OBJECT    Object[10];         /* Objects returned from search */
   ULONG     ulCount     = 10;   /* Count of objects to find / or found */
   WPFolder  *folder     = 0;    /* Pointer to folder for search */
   ULONG     errorid     = 0;    /* Error returned from previous search */
   CHAR      sz[CCHMAXPATH];     /* Title string to look for */
   PSZ       title = sz;
   Class[0] = _WPFolder;
   Class[1] = NULL;

   /* Get the pointer to the desktop (since that is where we are looking) */

   folder = _wpclsQueryFolder( _WPFolder, 'WP_DESKTOP', TRUE );

   _wpclsSetError( _WPObject, 0 );      /* Reset the error indicators */
   rc = 0;

         /* Attempt to find the first 10 objects matching our criteria */

   ulCount = 10;
   rc =_wpclsFindObjectFirst(_WPObject,     /* Class self pointer */
                             Class,         /* Pointer to array of class objects */
                             &hFind,        /* Handle for wpclsFindObjectNext */
                             NULL,          /* Find EVERYTHING */
                             folder,        /* Pointer to folder of interest */
                             TRUE,          /* Search all folders in tree */
                             NULL,          /* No extended criteria */
                             Object,        /* Array of object pointers */
                             &ulCount );    /* Number requested and number found */

   errorid = _wpclsQueryError( _WPObject);  /* Get errorid (may still be OK) */

   if ((!rc && (errorid == WPERR_BUFFER_OVERFLOW)) || rc) {

              /***** Process objects found here ******/

   } else {
      somPrintf( '_wpclsFindObjectFirst failed, errorid=%u\n', errorid );
      return;
   } /* endif */

   do {

      _wpclsSetError( _WPObject, 0 );    /* Reset error indicators */
      rc = 0;

             /* Look for next 10 objects */

      rc =_wpclsFindObjectNext(_WPObject,       /* Self */
                                hFind,          /* Handle from previous Find */
                                Object,         /* Objects found */
                                &ulCount );     /* Number to look for. On
                                                   return, number found */

      errorid = _wpclsQueryError( _WPObject );

      if ((!rc && (errorid == WPERR_BUFFER_OVERFLOW)) || rc) {

              /***** Process objects found here ******/

      } else {
            somPrintf('_wpclsFindObjectNext failed, errorid=%u\n', errorid);
            return;
      } /* endif */

   } while ( errorid == WPERR_BUFFER_OVERFLOW ); /* enddo */

   _wpclsSetError( _WPObject, 0 );    /* Reset error indicators */
   rc = 0;
               /* Indicate find complete */

   rc =_wpclsFindObjectEnd( _WPObject, hFind );

   if (!rc) {
     errorid = _wpclsQueryError( _WPObject );
     somPrintf( '_wpclsFindObjectEnd failed, errorid=%u\n', errorid );
     return;
   }
   return;
}

Related Methods