HBObject() > Methods for error handling xHarbour Developers Network  

oHBObject:error()

Creates a runtime error.

Syntax

oHBObject:error( <cDescription> , ;
                 <cClassName>   , ;
                 <cMethod>      , ;
                 <nGenCode>     , ;
                 <aArgs>          ) --> xReturn

Arguments

<cDescription>
This is a character string describing the error (see oError:description).
<cClassName>
This is the class name of the object (self:className()).
<cMethod>
This is a character string holding the name of the method currently being executed.
<nGenCode>
This is a numeric error code (see oError:genCode).
<aArgs>
This is an array holding the values involved with the runtime error (see oError:genCode).

Return

The method returns the value of the current error handling code block.

Description

Method :error() provides a convenient way for raising a runtime error within methods. The parameters passed to the method are filled into an Error() object which is passed to the current ErrorBlock().

A simple usage scenario for the :error() method is shown below. It reduces the amount of code for creating an Error() object by a great extent:

   #include "hbclass.ch"
   #include "Error.ch"

   PROCEDURE Main
      LOCAL obj := Test():new()

      ? obj:calc( 2, 9 )

      ? obj:calc( "ABCD", 0x77 )
   RETURN


   CLASS Test
      EXPORTED:
      METHOD Calc
   ENDCLASS

   METHOD calc( n1, n2 ) CLASS Test
      IF Valtype( n1 ) + Valtype( n2) <> "NN"
         RETURN ::error( "Type mismatch", ::className(), "calc", EG_ARG, {n1,n2} )
      ENDIF
   RETURN n1 * n2

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