_Error( ) API Library Routine
Signals the error specified by the value in code to the Visual FoxPro run time.
void _Error(int code)
int code; /* Internal Visual FoxPro
error number. */
Remarks
The code parameter is a Visual FoxPro internal error number and can be passed as a positive or negative value. _Error( ) gives control to the Visual FoxPro error handler so that the error can be handled like any other Visual FoxPro error. Control of program flow doesn't return to the routine that called _Error( ), even when the user chooses to ignore the error. Execution resumes at the next Visual FoxPro statement.
See the Visual FoxPro Error Numbers topic in Help for error numbers and their meanings.
Note
Do not use _Error() from an event handler.
For more information on how to create an API library and integrate it with Visual FoxPro, see Accessing the Visual FoxPro API.
Example
The following example calls _Error( ) when _DBSkip( ) returns an error number. The Visual FoxPro code shows how to cause _Error( ) to be called.
Visual FoxPro Code
SET LIBRARY TO ERROR
DO CreateTest
ON ERROR DO expectError
USE
= DBSKIP(1) && _Error() called: no DBF in use
USE test
GO TOP
= DBSKIP(-1)
= DBSKIP(-1) && _Error() called: at top of file
GO BOTT
= DBSKIP(1)
= DBSKIP(1) && _Error() called: at bottom of file
ON ERROR
PROCEDURE expectError
? "ERROR: " + MESSAGE()
RETURN
PROCEDURE CreateTest
CREATE TABLE test (ABC C(20))
APPEND BLANK
REPLACE ABC WITH "This is record 1"
APPEND BLANK
REPLACE ABC WITH "This is record 2"
APPEND BLANK
REPLACE ABC WITH "This is record 3"
APPEND BLANK
REPLACE ABC WITH "This is record 4"
GO TOP
RETURN
C Code
#include <pro_ext.h>
FAR Example(ParamBlk FAR *pblk)
{
int RetCode;
if ((RetCode = _DBSkip(-1, pblk->p[0].val.ev_long)) < 0) {
_PutStr("\nError encountered in example program.");
_Error(-RetCode); // _DBSkip() returns negative error code
}
_RetInt(RetCode, 10);
}
FoxInfo myFoxInfo[] = {
{"DBSKIP", (FPFI) Example, 1, "I"},
};
FoxTable _FoxTable = {
(FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};
See Also
Reference
_ErrorInfo( ) API Library Routine
_UserError( ) API Library Routine
_DBSkip( ) API Library Routine