'ErrorTrapTest.bas
'1) Can ON ERROR RESUME NEXT be turned ON/OFF at run-time using this technique?
'2) 'Why ever use RESUME NEXT?
'3) 'What errors would ON ERROR RESUME NEXT prevent from a GPF?
'
'This code will run under PBCC or PBWIN.
'Intentionally doesn't use ERRCLEAR to test ERR on return from CALL
'
------------------
'1) Can ON ERROR RESUME NEXT be turned ON/OFF at run-time using this technique?
'2) 'Why ever use RESUME NEXT?
'3) 'What errors would ON ERROR RESUME NEXT prevent from a GPF?
'
'This code will run under PBCC or PBWIN.
'Intentionally doesn't use ERRCLEAR to test ERR on return from CALL
'
Code:
#COMPILE EXE #DIM ALL DECLARE SUB TEST(Counter AS LONG) DECLARE SUB DISPLAY(MyText AS STRING) 'allow displaying in PBCC or PBWIN ' FUNCTION PBMAIN () AS LONG LOCAL Loops AS LONG FOR Loops = 1 TO 4 Test(Loops) Display "ERR value after returing from call" + STR$(ERR) NEXT #IF %DEF(%PB_CC32) DISPLAY "Press any key to exit" WAITKEY$ #ENDIF END FUNCTION ' SUB TEST(Counter AS LONG) LOCAL s AS STRING ON ERROR GOTO 0 'Assure error trapping is off IF Counter MOD 2 = 0 THEN ON ERROR RESUME NEXT 'Is this statement always active? s = "USING ON ERROR RESUME NEXT" ELSE s = "NO ON ERROR RESUME NEXT END IF OPEN "xx:fail.dat" FOR INPUT AS #1 IF ERR THEN DISPLAY s + " Error" + STR$(ERR) END IF END SUB SUB Display(MyText AS STRING) #IF %DEF(%PB_CC32) PRINT MyText #ELSE MSGBOX MyText #ENDIF END SUB
Comment