Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

COMReturnError()

You know those obnoxious error messages you get that say “OLE IDispatch exception code blah, blah, blah?” Well, now you don’t just have to be the poor hapless recipient of them—you can create your own and share the fun with others!

Usage

COMReturnError( cServerName, cErrorDescription )

Parameter

Value

Meaning

cServerName

Character

This string is returned in the error message and should describe your software.

cErrorDescription

Character

This string is returned in the error message after cServerName.

Use this function to generate errors in your custom COM servers. The function works only within COM components, and generates a “Feature not available” error if executed in normal code or from the Command Window. The error generated is always error 1429, and if no error handler is in place, the error is displayed as “OLE IDispatch exception code <number> from cServerName: cErrorDescription.” In VFP 6, this number is 0, but in VFP 7, it was changed to 1000. If you do have an error handler in place, you can use the AERROR() function to get more information in order to handle the error appropriately.

AError() returns seven values for an OLE Error 1429, but this command lets us set only two of them. It sure would be nice in a future version if Microsoft would consider letting us set the error code to something other than the suspicious-looking zero (in VFP 6) or plain vanilla 1000 (in VFP 7). Even better, it would be nice to be able to set all of the values.

Error 1429 is documented as returning the sixth element of AError() as either character or null. In our tests, it always came back as a numeric 0. If you're writing a generic error handler, look out for these type inconsistencies!

Example

COMReturnError("MyServer","MyErrorGenerator")

See Also

AError(), CreateObject(), CreateObjectEx(), Error Event, On Error