Navigation: Language Reference > 13 - Built-in Functions >====== POPERRORS (return error information) ====== | ![]() ![]() ![]() |
POPERRORS( )
POPERRORS | Returns the last error information saved by PUSHERRORS() |
The POPERRORS procedure restores the last error information that was saved by PUSHERRORS. This includes ERRORCODE(), ERROR(), FILEERRORCODE(), FILEERROR(), ERRORFILE(), the C library errno variable, and the current Windows error code returned by the GetLastError( ) API function. To read these errors, you need to use the appropriate support statements.
POPERRORS is especially useful for programmer's that use the GetLastError( ) API function. POPERRORS restores the Windows error code that had been saved by PUSHERRORS. GetLastError() will return the same error code after POPERRORS that it would have returned just prior to PUSHERRORS.
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: