On Tue, 04 Jul 2000 15:03:40 -0500, Rubywand wrote: > As expected, so long as there is no bad entry for X there is no change >between the first display (Line 10) and subsequent displays at Line 50. And, >if you enter a "1", the program exits; whereupon a CALL 768 gives the same >value for the pointer. (BTW, this value may be off a bit from the actual >value at the time of the CALL 768.) > > If you run the program and enter bad values for X (e.g. "0", letters, >etc.) the value for the stack pointer displayed at Line 50 marches downward >just as you say it should. Yes, if the error trapping is on and no error occurs then no info is pushed on the stack but if an error does occur while error trapping is on, then info is pushed onto the stack. > Something that's kind of interesting is that there are some commands >which automatically reset the stack pointer near the top. LOAD and NEW both >do this. That is interesting. However, I wouldn't rely on it. Besides, it is still better programming style to make sure your program doesn't mess up the stack in the first place. > CALL -3288 turns out to be unstable when an error occurs inside a >subroutine. That is, for some errors the stack is restored and for some it is >not and the program crashes. The way to work around this problem is to either disable error trapping in your subroutine, change the error trapping to point to a different line that will deal with being in a subroutine or keep a variable as a flag to indicate whether you are in a subroutine or not so the error trapping routine can deal with it. Here are examples of all three methods respectively: 9 REM Turn on error trapping 10 ONERR GOTO 100 20 GET X 30 GOSUB 80 39 REM Turn error trapping back on after subroutine returns 40 IF A = 1 THEN 10 49 REM Normal quit, the stack is fine so just turn off error trapping 50 POKE 216,0 70 END 79 REM Turn off error trapping during subroutine 80 POKE 216,0 90 A = 1 / x: RETURN 99 REM Got an error so clean up stack, turn of error trapping and end 100 CALL -3288: POKE 216,0 110 PRINT "ERROR" 120 END 9 REM Turn on error trapping 10 ONERR GOTO 100 20 GET X 30 GOSUB 80 39 REM Restore original error trapping after subroutine returns 40 IF A = 1 THEN 10 49 REM Normal quit, the stack is fine so just turn off error trapping 50 POKE 216,0 70 END 79 REM Change error trapping during subroutine 80 ONERR GOTO 97 90 A = 1 / X: RETURN 95 REM Got an error in the subroutine so clear error info and 96 REM return address off stack, turn off error trapping and end 97 CALL -3288: POP: POKE 216,0: GOTO 110 98 REM Got an error in the main part of the program so clean up stack, 99 REM turn of error trapping and end 100 CALL -3288: POKE 216,0 110 PRINT "ERROR" 120 END 4 REM Set flag that we are in main part of program 5 SF = 0 9 REM Turn on error trapping 10 ONERR GOTO 100 20 GET X 30 GOSUB 80 39 REM Turn error trapping back on after subroutine returns 40 IF A = 1 THEN 10 49 REM Normal quit, the stack is fine so just turn off error trapping 50 POKE 216,0 70 END 79 REM Set flag to say we are in a subroutine 80 SF = 1 90 A = 1 / x: RETURN 99 REM Got an error so clean up stack, turn of error trapping and end 100 CALL -3288: POKE 216,0 104 REM Clear return address off stack if needed 105 IF SF = 1 THEN POP 110 PRINT "ERROR" 120 END +------------------------------------------------------------------------+ | Jeff Blakeney - Dean of the Apple II University in A2Pro on Delphi | | Delphi Apple II Forums Web Pages | | A2: http://www.delphi.com/apple2 A2Pro: http://www.delphi.com/a2pro | +------------------------------------------------------------------------+