Programming Guide:xppguide

Handling errors Foundation

Obtaining error information

The Xbase++ runtime system maintains an internal error status for operations performed by the automation sub-system. The functions ComLastError() and ComLastMessage() can be used to determine the error status of the last COM/ActiveX operation performed. This information is useful in situations where the reason for a certain error is not readily obvious.

If the functions GetObject() or CreateObject() fail, the value NIL is returned, for example. To get information about the reason why the COM/ActiveX component could not be created or accessed, ComLastError() and/or ComLastMessage() should be used.

Runtime errors

If an error occurs involving a COM/Active component, a regular Xbase++ runtime error is generated.

When using COM/ActiveX, common causes for runtime errors are:

- Attempting to access non-existing methods or properties of a COM/ActiveX component

- Attempting to assign a code block to a non-existing event callback slot

- Passing incorrect parameters to a COM/ActiveX method or property

- Using a COM/ActiveX component or control that is not installed on the computer or that is installed incorrectly

- Attempting to perform an operation that violates an internal protocol of the COM/ActiveX component. For instance, a connection object may not support sending data if the network is currently unavailable. Such prerequisites should be listed in the documentation that accompanies the COM/ActiveX component.

Catching errors

COM/ActiveX-specific errors are in no way different from the errors raised from other run-time system components. To handle runtime errors generated by COM/ActiveX, the normal error-handling strategies can be applied. In most cases, this involves using a BEGIN SEQUENCE..END control structure to protect sensitive code. Furthermore, a code block that calls a custom error routine is often specified via the function ErrorBlock().

The following code snippet illustrates how an application might handle the case that an ActiveX control cannot be created. The code was taken from the example \SOURCE\SAMPLES\ACTIVEX\ACROBAT\MAIN.PRG.

(...) 

oControl := XbpActiveXControl():new( oForm:drawingArea ) 
oControl:CLSID := "{CA8A9780-280D-11CF-A24D-444553540000}" 

// Create ActiveX control. Use BEGIN/END 
// SEQUENCE to handle eventual errors, eg. 
// due to a missing component. 
bOldError := ErrorBlock( {|e| Break(e)} ) 

BEGIN SEQUENCE 
   oControl:create(,, {10,60},{610,370} ) 
RECOVER USING oError 
   ErrorBlock( bOldError ) 
   MsgBox( "Error creating ActiveX control. Please make sure" + CRLF +; 
           "Acrobat Reader is installed on your computer.",           ; 
           "Acrobat Reader Sample" ) 
   QUIT 
END SEQUENCE 

ErrorBlock( bOldError ) 

(...) 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.