Function ErrorBlock() Foundation
Defines a code block to execute if a runtime error occurs.
ErrorBlock( [<bErrorHandler>] ) --> bLastErrorHandler
When <bErrorHandler> is not specified, the function ErrorBlock() returns the current code block which would be executed if a runtime error occurred. If a new code block is specified, the old one is returned and the new one is set in its place for subsequent error handling.
The function ErrorBlock() is a very efficient function for the treatment of runtime errors. It is frequently used with the control structure BEGIN SEQUENCE..END. Using ErrorBlock(), a code block is specified which calls an error handling routine. Individual error handling routines can be defined in a program to make the program independent of the default error routines in Xbase++. The default routine is part of the runtime library of Xbase++ (see the file ERRORSYS.PRG). If a runtime error occurs, the default handler displays information about the kind of error, sets ErrorLevel() to the value 1 and ends the program with QUIT.
If it is desireable to use a different routine for default error handling, a different ErrorSys() function should be written. This function should call ErrorBlock() to install a code block that calls the desired default error handler. Since ErrorSys() is automatically called on application startup, this method insures that the appropriate code block is installed prior to the start of the actual application.
The code block should receive at least one parameter. A system generated error object containing information about the runtime error that occurred will be passed as this parameter. Common examples for an error code block are:
The code block calls a function and passes the error object on to it. Instead of a single function, the code block can contain a list of expressions but this is rarely as useful.
The return value of the code block (or of the error function) determines further handling of the runtime error. When a failed operation can be repeated, it is retried if the return value is .T. (true). If the return value is .F. (false) the program continues without retrying the failed operation.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.