Error Event
You could write a book about error handling in Visual FoxPro. In fact, we wish someone would. There are multiple ways to tackle the issues involved. The Error event is one part of the picture—it fires when an error occurs in any method of an object.
Usage |
PROCEDURE oObject.Error LPARAMETERS [ nIndex, ] nError, cMethod, nLine |
Parameter |
Value |
Meaning |
nIndex |
Numeric |
If the object is a control array, which item in the array fired the event? |
nError |
Numeric |
The error number. |
cMethod |
Character |
The name of the method that caused the error. |
nLine |
Numeric |
The line number on which the error occurred. |
The bad news is what happens if an error occurs in the Error method. Does it call your ON ERROR handler? Nope, you get the usual FoxPro Cancel/Suspend/Ignore dialog. Better debug those Error methods really well before you send them out to users. |
Error 1116, "Too many windows are open," does not invoke the Error method, nor does it fire the ON ERROR handler. We sort of understand why. This error is a resource issue, but there's no guarantee that our error handlers will need any more windows, so why not give us a shot at it? |
Example |
* For an OLE control, we might trap OLE errors locally. PROCEDURE oleMyGeneral.Error LPARAMETERS nError, cMethod, nLine IF nError = 1427 or nError = 1429 && OLE errors LOCAL ARRAY aErrInfo[1] = AERROR(aErrInfo) * Now figure out how to handle this OLE error. ELSE * Call the application's error handler. oApp.HandleError(This.Name,nError,cMethod,nLine) ENDIF RETURN |
See Also |