Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!ifistg!koppenh From: koppenh@dia.informatik.uni-stuttgart.de (Andreas Koppenhoefer) Newsgroups: comp.sys.apple2 Subject: Re: Stacks, Basic, and Onerr Message-ID: Date: 21 Mar 91 17:54:55 GMT References: <9103191800.AA11676@apple.com> Sender: news@ifistg.uucp Organization: Informatik, Univ. Stuttgart. W.Germany Lines: 51 In-reply-to: TSEMM@ALASKA.BITNET's message of 19 Mar 91 17:57:12 GMT In article <9103191800.AA11676@apple.com> TSEMM@ALASKA.BITNET ("Edward M. Moore") writes: Path: ifistg!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac,att!ucbvax!ALASKA.BITNET!TSEMM From: TSEMM@ALASKA.BITNET ("Edward M. Moore") Newsgroups: comp.sys.apple2 Date: 19 Mar 91 17:57:12 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 7 I'm trying to design a program using gosubs. One of the sections is where I have a file-handeling (loading a shape table) from disk. I would like to use OnErr Goto in order to handle the error, but when that happens I loose my stack of gosubs. How can this be prevented? TSEMM@ALASKA TSEMM@ALASKA.bitnet There is no need to use any machine language, CALL or POKE. Just look at the following code, which tries to bload some stuff into memory. 10 PRINT "CALLING SUBROUTINE" 20 GOSUB 100 30 PRINT "FINISHED":END ... 100 ONERR GOTO 150 110 ER = 1 : IF ER THEN PRINT CHR$(4)"BLOAD STUFF" 120 POKE 216,0 : IF NOT ER THEN PRINT "CANNOT LOAD FILE 'STUFF'";CHR$(7) 130 RETURN 150 POKE 216,0: IF ER THEN ER = 0 : RESUME : REM error in line 110! 160 PRINT "THERE IS AN UNEXPECTED ERROR":REM This should not happen! 170 STOP Think about it and try it. It will work under every applesoft basic I know. Remarks: If DOS or PRODOS returns an error for the BLOAD command, then basic will continue with the error handler in 150. The following RESUME tries to restart the basic commands that caused the error. It's the IF statement in 110 and not the PRINT statement in the same line. The interpreter thinks about an 'IF THEN ' as a single statement!!! BUT now the variable ER is set to zero, the if-clause evals to false and the interpreter jumps to the next line in 120. All your stack contents (RETURN-addresses, etc.) remains intact! Greetings Andreas -- Andreas Koppenhoefer, Student der Universitaet Stuttgart, BR Deutschland X400: koppenh@dia.informatik.uni-stuttgart.dbp.de SMTP: koppenh@dia.informatik.uni-stuttgart.de privat: Belaustr. 5/3, W-7000 Stuttgart 1, Germany, +49 711 694111 (18-22h MEZ)