AError()
This function, added in VFP 3, consolidated many of the separate functions found in FoxPro 2.x. Instead of remembering the names of a bunch of different functions that return bits and pieces of information when an error occurs (all those are still available, if you care to use them), you can use this function to put all the necessary information into a single array. Best of all, AERROR() can even be used to find out about errors that occur when Visual FoxPro talks to the rest of the world via OLE or ODBC.
Usage |
nRows = AError( ErrorInfo ) |
When an error is triggered because a field validation rule fires, the third column should get the name of the field. However, in VFP 5 and later, instead the third column contains the validation message (as does SYS(2018), the function this column is meant to replace). Starting in VFP 5.0a, the fifth column contains the field number, so there is some way to get at the information, but we sure wish they'd fix this one instead of telling us it's "by design." |
Example |
ON ERROR DO Handler * Now force some errors. XYZ USE NoSuchTable oWord = CREATEOBJECT("Word.Application") oWord.Documents.Open("NoSuchFile") RELEASE oWord * Substitute the name of a data source that exists * on your system in the next line. nHandle = SQLCONNECT("Access With ODBC 2.0") IF SQLEXEC(nHandle, "SELECT * FROM NoSuchTable") < 1 DO Handler ENDIF = SQLDISCONNECT(nHandle) ON ERROR PROCEDURE Handler * Handle errors that occur. * In this case, we'll just figure out which kind they are * and then save the information to a file. LOCAL aErrData[1] = AERROR(aErrData) DO CASE CASE aErrData[1,1] = 1526 * ODBC Error WAIT WINDOW "ODBC Error Occurred" NOWAIT CASE BETWEEN(aErrData[1,1], 1426, 1429) * OLE Error WAIT WINDOW "OLE Error Occurred" NOWAIT OTHERWISE * FoxPro error WAIT WINDOW "FoxPro Error Occurred" NOWAIT ENDCASE LIST MEMORY TO FILE ErrInfo.TXT ADDITIVE NOCONSOLE RETURN |
See Also |