Wiki Home

a Error


Namespace: WIN_COM_API
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.

function xErrHlr()
#DEFINE CRLF chr(13)+chr(10)
local ;
	laErrs[1], lnErrs, lnErr, ;
	llOleErr, llOdbcErr, llTrigErr, ;
	lcErrMsg
	
aError( laErrs )
llOleErr = between( laErrs[1], 1426, 1429 )
llOdbcErr = laErrs[1] = 1526
llTrigErr = laErrs[1] = 1539

lcErrMsg = ;
	'1. Error: ' + trans( laErrs[1] ) + CRLF ;
	+ '2. Message: "' + laErrs[2] + '"' + CRLF ;
	+ '3. ' + iif( llOleErr or llOdbcErr, "OLE/ODBC: ", "EMP: " ) + transform( laErrs[3] ) + CRLF ;
	+ '4. ' + iif( llOleErr, "App: ", ;
		iif( llOdbcErr, "SQL State: ", ;
		"Work Area (?): " ) + transform( laErrs[4] ) ) + CRLF ;
	+ '5. ' + iif( llOleErr, "OLE Help file: " + trans( laErrs[5] ), ;
		+ iif( llOdbcErr, "ODBC Error: " + transform( laErrs[5] ), ;
		+ iif( llTrigErr, "Trigger: " + substr( "InsertUpdateDelete", laErrs[5]*6-5, 6 ), ;
		+ "na: " + transform( laErrs[5] ) ) ) ) + CRLF ;
	+ '6. ' + iif( llOleErr, "OLE Help Context Id : ", ;
		+ iif( llOdbcErr, "ODBC Connection Handle: ", ;
		+ "na: " ) ) + transform( laErrs[6] ) + CRLF ;
	+ '7. ' + iif( llOleErr, "OLE exception number: ", ;
		+ "na: " ) + transform( laErrs[6] )
		
? lcErrMsg
_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 1
Error "my error"

On Error

Select * from ErrorLog into cursor foo
Browse width 20
Return

Procedure LogError
Lparameters ttTimeStamp, tnLineNo, tcFileName
Local lnErrors, lnError
Local array laErrors[1]

lnErrors = AError(laErrors)
For lnError = 1 to lnErrors
	Insert into errorlog ;
		( tTimeStamp, nError, cErrorText, nLineNo, cFileName ) ;
	values ;
		( ttTimeStamp, laErrors[lnError,1], laErrors[lnError,2], tnLineNo, tcFileName )
EndFor

Return

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 AERROR: http://stevenblack.com/VFPCMDaerror.ASP
Contributors Carl Karsten
Category Error
( Topic last updated: 2006.03.25 05:42:50 AM )