[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 Error
 Provides objects containing information about runtime errors
------------------------------------------------------------------------------
 Description

     An Error object is a simple object that contains information pertaining
     to a runtime error.  Error objects have no methods, only exported
     instance variables.  When a runtime error occurs, CA-Clipper creates a
     new Error object and passes it as an argument to the error handler block
     specified with the ERRORBLOCK() function.  Within the error handler, the
     Error object can then be queried to determine the nature of the error
     condition.

     Error objects can also be returned to the RECOVER statement of a BEGIN
     SEQUENCE construct with a BREAK statement.  Here, the error object can
     be queried for local error handling.  For more detailed information and
     examples refer to the "Error Handling Strategies" chapter in the
     Programming and Utilities Guide.

 Examples

     .  This example demonstrates how a file open operation might be
        handled in an error handler replicating the default CA-Clipper
        behavior.  When, for example, an attempt to open a database file with
        a USE command fails, control returns to the statement following the
        offending command:

        #include "Error.ch"
        #command RETRY      => RETURN (.T.)   // Retry operation
        #command RESUME      => RETURN (.F.)   // Default recovery
        //

        FUNCTION MyError( <oError> )
           //
           // Handle file open error
           IF <oError>:genCode == EG_OPEN .AND.;
              <oError>:canDefault .AND.;
              NETERR()
              //
              RESUME
           ENDIF
           .
           . <other error statements>
           .
           RETURN NIL

     .  This example retries an operation within an error handler a
        specified number of times:

        #include "Error.ch"
        #command RETRY      => RETURN (.T.)   // Retry operation
        #command RESUME      => RETURN (.F.)   // Default recovery
        //

        FUNCTION MyError( <oError> )
           //
           // Handle printer not ready error
           IF <oError>:genCode == EG_PRINT .AND.;
              <oError>:canRetry .AND.;
              <oError>:tries < 25
              //
              RETRY
           ENDIF
           .
           . <other error statements>
           .
           RETURN NIL

     .  This code fragment returns an error object from an error
        handler to the RECOVER statement for further processing:

        LOCAL objLocal, bLastHandler
        //
        // Save current and set new error handler
        bLastHandler := ERRORBLOCK({    |oErr| ;
                          MyHandler(oErr, .T.)})
        //
        BEGIN SEQUENCE
           .
           . <operation that might fail>
           .
        RECOVER USING objLocal
           .
           . <send messages to objLocal and handle the error>
           .
        END
        //
        // Restore previous error handler
        ERRORBLOCK( bLastHandler )

        FUNCTION MyHandler( <oError>, lLocalHandler )
           //
           // Handle locally returning the error object
           IF lLocalHandler
              BREAK <oError>
           ENDIF
           .
           . <other statements to handle the error>
           .
           RETURN NIL

 Files   Header file is Error.ch, default error handler is in Errorsys.prg.

See Also: BEGIN SEQUENCE DOSERROR() ERRORBLOCK() NETERR()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson