| HBObject() > Methods for error handling |
![]() |
![]() |
![]() |
Creates a runtime error.
oHBObject:error( <cDescription> , ;
<cClassName> , ;
<cMethod> , ;
<nGenCode> , ;
<aArgs> ) --> xReturn
The method returns the value of the current error handling code block.
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
http://www.xHarbour.com