The elements of the array populated by aError()
If an element is not applicable (3-7), it is null.
1 (n) The number of the error. Identical to the value returned by ERROR( ). (Ole Errors 1426 - 1429; Odbc error: 1526, trigger failed: 1539)
2 (c) The text of the error message. Identical to the value returned by MESSAGE( ).
3 (c) If the error has an additional error parameter, contains the text of the error parameter. Identical to the value returned by SYS(2018). OLE and ODBC: The text of the OLE/ODBC error message.
4 (?|c) As appropriate (what???), contains the number of the work area in which the error occurred. OLE: (c) The application name (example, "Microsoft Excel"); ODBC: (c) The current ODBC SQL state.
5 (c|n) OLE: (c) Contains the name of the application's Help file where more information about the error can be found if the information is available from the application. ODBC: (n) The error number from the ODBC data source; Trigger failed: (n) 1 = Insert, 2 = Update, 3 = Delete.
6 (c|n) OLE: (c) Contains the Help context ID for the appropriate Help topic if the information is available from the application; otherwise contains the null value. ODBC: (n) The ODBC connection handle.
7 (n) OLE: An OLE 2.0 exception number.
Here is some code to construct a string using the above info.
#DEFINE CRLF chr(13)+chr(10)
laErrs, lnErrs, lnErr, ;
llOleErr, llOdbcErr, llTrigErr, ;
aError( laErrs )
llOleErr = between( laErrs, 1426, 1429 )
llOdbcErr = laErrs = 1526
llTrigErr = laErrs = 1539
lcErrMsg = ;
'1. Error: ' + trans( laErrs ) + CRLF ;
+ '2. Message: "' + laErrs + '"' + CRLF ;
+ '3. ' + iif( llOleErr or llOdbcErr, "OLE/ODBC: ", "EMP: " ) + transform( laErrs ) + CRLF ;
+ '4. ' + iif( llOleErr, "App: ", ;
iif( llOdbcErr, "SQL State: ", ;
"Work Area (?): " ) + transform( laErrs ) ) + CRLF ;
+ '5. ' + iif( llOleErr, "OLE Help file: " + trans( laErrs ), ;
+ iif( llOdbcErr, "ODBC Error: " + transform( laErrs ), ;
+ iif( llTrigErr, "Trigger: " + substr( "InsertUpdateDelete", laErrs*6-5, 6 ), ;
+ "na: " + transform( laErrs ) ) ) ) + CRLF ;
+ '6. ' + iif( llOleErr, "OLE Help Context Id : ", ;
+ iif( llOdbcErr, "ODBC Connection Handle: ", ;
+ "na: " ) ) + transform( laErrs ) + CRLF ;
+ '7. ' + iif( llOleErr, "OLE exception number: ", ;
+ "na: " ) + transform( laErrs )
_cliptext = lcErrMsg && put it on the clipboard so you can post it in a message.
This one logs errors to a table.
CREATE TABLE ErrorLog ( ;
pkErrorLog i autoinc, ;
tTimeStamp t, ;
nError i, ;
cErrorText c(200), ;
nLineNo i, ;
cFileName c(200) )
On Error do LogError with Datetime(), Lineno(), Program()
x = BadVar
Error "my error"
Select * from ErrorLog into cursor foo
Browse width 20
Lparameters ttTimeStamp, tnLineNo, tcFileName
Local lnErrors, lnError
Local array laErrors
lnErrors = AError(laErrors)
For lnError = 1 to lnErrors
Insert into errorlog ;
( tTimeStamp, nError, cErrorText, nLineNo, cFileName ) ;
( ttTimeStamp, laErrors[lnError,1], laErrors[lnError,2], tnLineNo, tcFileName )
If you get 1539 (trigger failed), the default RI code stores information in ga Error.
More COM error information can be obtained using the aError function. The VFP documentation for aError states that the 7th element of the returned array is the OLE 2.0 exception number but when using the MSComm32 control I noticed that this value was always 0 and that the 6th element was the one that matched the error constants listed in the control help documentation. -- ComError
A bug in the sys(2018) and aerror() functions in VFP 5 (including 5.0a) prevents the actual field name from being available when a field rule is violated. Fortunately, in VFP 5.0a, an undocumented feature of aerror() is that element 5 of the array it creates contains the field number, from which we can determine the field name. From "Error Handling in Visual FoxPro" by Doug Hennig.
Is this still a bug in VFP6? -- CFK
If the type function is called before calling aerror the "parameter" in element 3 of the array, which is also placed in the error message in element 2, can get replaced by some other string. ("FORM" was substituted in one case were type was used to see if thisform was an object before calling aerror.) The vartype function does not cause this problem. -- James HHansen
See also the Internationalization gotchas for
Contributors Carl Karsten