xHarbour Reference Documentation > Statement Reference xHarbour Developers Network  

ERROR HANDLER

Declares the method for error handling within a class.

Syntax

ERROR HANDLER <MethodName>

Arguments

<MethodName>
This is the symbolic name of the error handling method. It must begin with a letter or underscore followed by digits, letters or underscores. The symbolic name can contain up to 63 characters.

Description

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.

Info

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

Example

// 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 )

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe