User Tools

Site Tools


pusherrors_write_error_information_.htm
Navigation:  Language Reference > 13 - Built-in Functions >====== PUSHERRORS (write error information) ====== Previous pageReturn to chapter overviewNext page

PUSHERRORS( )

blk2blue.jpg

PUSHERRORS Writes the last error information to an internal memory stack.

The PUSHERRORS procedure writes the current error states of the current thread's ERRORCODE(), ERROR(), FILEERRORCODE(), FILEERROR(), ERRORFILE(), the C library errno variable, and the current Windows error code returned by the GetLastError() API function.

POPERRORS is used to restore the error states originally saved by PUSHERRORS. The main purpose of these functions is to save errors states and then check them later, after performing some additional code that can potentially change them.

PUSHERRORS and POPERRORS works using the LIFO (last in, first out) stack convention. The maximum depth of the stack is dependent on available memory. Because ERRORCODE(), ERROR(), etc. are thread dependent, PUSHERRORS and POPERRORS statements that are called from different threads are independent of each other, and allocate a different memory stack for each thread.

Example:

   PROGRAM

   MAP

    InitialErrors()

   END

TESTFILE    FILE,DRIVER('DOS')

            RECORD

f1            BYTE

            END

           END

   CODE

   !file processing and initialization here

   OPEN(testfile)   !forcing an error

  PUSHERRORS()

   !additional code here

   InitialErrors

InitialErrors       PROCEDURE

ERRORCODEVAR        LONG

ERRORVAR            CSTRING(255)

FILEERRORCODEVAR    LONG

FILEERRORVAR        CSTRING(255)

ERRORFILEVAR        CSTRING(255)

Window WINDOW('Error Report'),AT(,,362,128),FONT('MS Sans Serif',8,,FONT:regular,CHARSET:ANSI),SYSTEM, |

        GRAY

      PROMPT('ERRORCODE:'),AT(9,10),USE(?Prompt1)

      STRING(@N_4),AT(97,10,43,10),USE(ERRORCODEVAR)

      PROMPT('ERROR:'),AT(9,25),USE(?Prompt2)

      STRING(@s40),AT(96,25),USE(ERRORVAR)

      PROMPT('FILEERRORCODE:'),AT(9,40),USE(?Prompt3)

      STRING(@N_4),AT(95,40),USE(FILEERRORCODEVAR)

      PROMPT('FILEERROR:'),AT(9,55),USE(?Prompt4)

      STRING(@S40),AT(95,55),USE(FILEERRORVAR)

      PROMPT('ERRORFILE:'),AT(9,70),USE(?Prompt5)

      STRING(@S40),AT(95,71),USE(ERRORFILEVAR)

    END

       CODE

       POPERRORS()

       ERRORCODEVAR     = ERRORCODE()     !will return 2

       ERRORVAR         = ERROR()         !will return “File Not Found”

       FILEERRORCODEVAR = FILEERRORCODE()

       FILEERRORVAR     = FILEERRORCODE()

       ERRORFILEVAR     = ERRORFILE()     !will return “TESTFILE”

       OPEN(WINDOW)

        ACCEPT

         DISPLAY

        END

See Also:

POPERRORS

pusherrors_write_error_information_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1