Syntax
Error():New( [cSubSystem], [nGenCode], [nSubCode], [cOperation], [cDescription], [aArgs] ) --> oError
ErrorNew( [cSubSystem], [nGenCode], [nSubCode], [cOperation], [cDescription], [aArgs] ) --> oErrorArguments
cSubSystem
is the name of the subsystem that raises the error.
nGenCode
is the general error code.
nSubCode
is the error code of the subsystem.
cOperation
is the name of the failed function or operation.
cDescription
is the text that describes the error.
aArgs
is an array with the arguments of the failed function or operator.
Return value
A new Error object. Every argument is optional; a variable without an argument keeps its initial value.
Description
An Error object holds the information about one runtime error. The runtime creates it when an error occurs and passes it to the block of ErrorBlock(). A program can also create its own Error object.
ErrorNew() is the same as Error():New().
A new object has empty texts, 0 in the numbers, .F. in the logical variables and NIL in args and cargo. The variables can be read and changed:
argsarray with the arguments of the failed function or operatorcanDefault.T. when the default recovery is availablecanRetry.T. when the failed operation can be tried againcanSubstitute.T. when a new result can replace the failed onecargoany value of the programdescriptiontext that describes the errorfilenamename of the file connected with the errorgenCodegeneral error codeoperationname of the failed function or operationosCodeerror code of the operating systemseverityseverity of the errorsubCodeerror code of the subsystemsubSystemname of the subsystem that raised the errortriesnumber of attempts of the failed operation
Notes
The variables have types. A text assigned to genCode or a number assigned to description is a runtime error. cargo takes any value.
Example
PROCEDURE Main()
LOCAL oError
LOCAL oCaught
LOCAL bPrevious
LOCAL xNumber := 1
// a new Error object, filled one variable at a time
oError := Error():New()
oError:subSystem := "MYLIB"
oError:subCode := 2001
oError:description := "File not found"
oError:filename := "data.dbf"
QOut( oError:subSystem + " " + LTrim( Str( oError:subCode ) ) + ": " + oError:description + " (" + oError:filename + ")" )
// ErrorNew() creates and fills the object in one line
oError := ErrorNew( "MYLIB", 21, 2002, "Save", "Disk full" )
QOut( oError:subSystem + " " + LTrim( Str( oError:subCode ) ) + ": " + oError:description )
// a runtime error arrives as an Error object
bPrevious := ErrorBlock( {| oFailure | Break( oFailure ) } )
BEGIN SEQUENCE
Upper( xNumber )
RECOVER USING oCaught
QOut( LTrim( Str( oCaught:subCode ) ) + ": " + oCaught:description )
ENDSEQUENCE
ErrorBlock( bPrevious )
RETURNOutput
MYLIB 2001: File not found (data.dbf)
MYLIB 2002: Disk full
1102: Argument error