| xHarbour Reference Documentation > Statement Reference |
![]() |
![]() |
![]() |
Declares the method for error handling within a class.
ERROR HANDLER <MethodName>
The ERROR HANDLER statement can only be used within the class declaration between CLASS and ENDCLASS. It declares a method that replaces the default method invoked when an object receives a message not declared in the object's class or super class(es).
A message is not understood by an object, when the message name identifies neither a declared member variable nor a declared method in the class or its super classes.
The default method for handling such an error condition is :msgNotFound( <cMsg> ).
The implementation of the error handling method must follow the ENDCLASS statement using METHOD, just as with regular methods.
| See also: | CLASS, DESTRUCTOR, METHOD (implementation) |
| Category: | Class declaration , Declaration , xHarbour extensions |
| Header: | hbclass.ch |
| Source: | vm\classes.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example implements an error handler which collects
// the message sent to an object along with parameters and forwards
// them to the overloaded :msgNotFound() method. All messages
// sent to the object in Main do not exist in the Test class.
#include "HbClass.ch"
PROCEDURE Main
LOCAL obj := Test():new()
? obj:one
? obj:two := 2
? obj:three( 1, 2, 3 )
RETURN
CLASS Test
EXPORTED:
METHOD msgNotFound
ERROR HANDLER noMessage
ENDCLASS
METHOD msgNotFound( cMessage, aParams ) CLASS Test
LOCAL x
? "Message not found:", cMessage
FOR EACH x IN aParams
?? "" , ValToPrg( x )
NEXT
RETURN self
METHOD noMessage( ... ) CLASS Test
LOCAL aParams := HB_AParams()
RETURN ::msgNotFound( __GetMessage(), aParams )
http://www.xHarbour.com