| xHarbour Reference Documentation > Class Reference (textmode) |
![]() |
![]() |
![]() |
Creates a new Error object.
Error( [<cSubSystem>] , ;
[<nGenCode>] , ;
[<nSubCode>] , ;
[<cOperation>] , ;
[<cDescription>], ;
[<aArgs>] , ;
[<cModuleName>] , ;
[<cProcName>] , ;
[<nProcLine> ] ) --> oError
The function returns a new Error object, optionally filled with information about a runtime error.
Objects of the Error class are used for error handling and error recovery by the xHarbour runtime system. An Error object is created when a runtime error occurs. Information about a runtime error is assigned to instance variables of the object before an exception is triggered by the runtime system. The Error object is then passed to the error handling routine programmed in the xHarbour application.
There are two statements available for user-defined error handling routines: BEGIN SEQUENCE and TRY...CATCH. See these statements for examples of local error handling.
Note: the default error handling routine is function DefError() implemented in the file source\rtl\ErrorSys.prg
| See also: | BEGIN SEQUENCE, DosError(), ErrorBlock(), FError(), HB_LangErrMsg(), Neterr(), TRY...CATCH, Throw() |
| Category: | Object functions |
| Header: | Error.ch |
| Source: | rtl\terror.prg, rtl\error.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example is a code snippet from the file WIN32OLE.PRG.
// It demonstrates how a runtime error can be handled using the
// TRY...CATCH statements and how to fill an Error object with
// information about a runtime error.
METHOD OleValuePlus( xArg ) CLASS TOleAuto
LOCAL xRet, oErr
TRY
xRet := ::OleValue + xArg
CATCH
oErr := ErrorNew()
oErr:Args := { Self, xArg }
oErr:CanDefault := .F.
oErr:CanRetry := .F.
oErr:CanSubstitute := .T.
oErr:Description := "argument error"
oErr:GenCode := EG_ARG
oErr:Operation := '+'
oErr:Severity := ES_ERROR
oErr:SubCode := 1081
oErr:SubSystem := "BASE"
RETURN Throw( oErr )
END
RETURN xRet
http://www.xHarbour.com