[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Please help with BinSCII
On Thu, 06 Jul 2000 04:44:50 GMT, CUTblakeney@home.com (Jeff Blakeney)
wrote:
>On Tue, 04 Jul 2000 15:03:40 -0500, Rubywand <rubywand@swbell.net>
>wrote:
>
>> 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:
Dang it! In the first two examples change line 40 to:
40 IF A <> 1 THEN 10
and in the last example we need to make a few alterations. We need to
clear the subroutine flag after coming back from the subroutine so we
need to change line 4 and 5 to 14 and 15 respectively and change line
40 to:
40 IF A <> 1 THEN 15
Also, I made the second example overly complex looking so I've fixed
it up a little. Here are the corrected programs:
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 130
90 A = 1 / X: RETURN
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
128 REM Got an error in the subroutine so clear error info and
129 REM return address off stack, turn off error trapping and end
130 CALL -3288: POP: POKE 216,0
140 PRINT "ERROR IN SUBROUTINE"
150 END
9 REM Turn on error trapping
10 ONERR GOTO 100
14 REM Set flag that we are in main part of program
15 SF = 0
20 GET X
30 GOSUB 80
38 REM Don't re-enable error trapping, just clear subroutine flag and
39 REM continue looping
40 IF A <> 1 THEN 15
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 |
+------------------------------------------------------------------------+