KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using error codes from PA_GetLastError
PRODUCT: 4D Open | VERSION: 6.7 | PLATFORM: Mac & Win
Published On: September 7, 2001

When writing a plug-in you should use PA_GetLastError in several places in your code. The reason for this is that most API calls in 4D will return an error code, or will return eER_NoErr, which is equal to zero. By using PA_GetLastError you can check if your code is functioning correctly and trap any errors that occur. For a list of the Error Codes please review the "4D Plug-in API Reference" document on page 733. Most commands listed in the API Reference will also inform you of what type of error is returned for the call in the section called "Error Handling".

For example, let's say we are initializing and allocating a PA_Handle. Notice how we are checking the error returned from the call to PA_NewHandle. If the handle is created without any problems we can then initialize it.

typedef struct
{
 long magicNumber;
 long dataSize;
 char data[1];
} MyStruct, *MyStructPtr, **MyStructHdle;


short err = eER_NoErr;
MyStructHdle h;
 // Allocate the handle
h = (MyStructHdle) PA_NewHandle(sizeof(MyStruct));
 // Check the error
err = PA_GetLastError();
if(!err)
{
 // OK, the handle was allocated. We can initialize it.
 (*h)->magicNumber = 'TITI';
 (*h)->dataSize = 1;
 (*h)->data[0] = 0;
}
return h;

Note: This example was taken from the "4D Plug-in API Reference" document on page 245.