--- title: "ON ERR Programming" type: "article" slug: "on-err-programming" url: "http://localhost/article/on-err-programming/" markdown_url: "http://localhost/article/on-err-programming.md" published_at: "2020-10-27T17:13:46+00:00" modified_at: "2026-07-26T12:03:05+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "A person whom I'd never heard of sent me a cassette, saying that it contained an important program that \"hangs up every time it is loaded\". I loaded the program and sure enough it did hang up. A touch of the NMI button on the Oliger DOS board gave me \"O.K\" at the screen bottom.…" category: - name: "Update Magazine" slug: "update-magazine" taxonomy: "category" url: "http://localhost/category/periodicals/update-magazine/" post_tag: - name: "Best of Timex/Sinclair 2068 Articles and Documents" slug: "ts2068best" taxonomy: "post_tag" url: "http://localhost/tag/ts2068best/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" indiv: - name: "Bill Jones" slug: "bill-jones" taxonomy: "indiv" url: "http://localhost/indiv/bill-jones/" publication: "Update Magazine" publication_r: id: 10283 title: "Update Magazine" type: "periodical" url: "http://localhost/periodical/update-magazine/" authors: "Bill Jones" authors_r: - name: "Bill Jones" slug: "bill-jones" taxonomy: "indiv" url: "http://localhost/indiv/bill-jones/" issues_articles: - id: 26511 title: "Update October 1988" type: "issue" url: "http://localhost/issue/ts-2068-up-date-october-1988/" pages: "14-15" pubdate: "October 1988" archive_link: false volumeissue: "vn" --- # ON ERR Programming A person whom I’d never heard of sent me a cassette, saying that it contained an important program that “hangs up every time it is loaded”. I loaded the program and sure enough it did hang up. A touch of the NMI button on the Oliger DOS board gave me “O.K” at the screen bottom. Then LIST put the listing on screen where I discovered `` in the first program line. I EDITed the line and removed the ON ERR, then found a subscript error in a following program line. The moral of this story is that if you use `` you’d better have every conceivable error eliminated. I returned the cassette with the ON ERR removed and the program re-saved, with expanations, never to hear from my pen pal again: no thanks, no nuttings. AND, I paid the postage. The morale of that story is, if you ask someone to do something for you and he does it, you should thank him. The TS-2068 “Remembers ON ERR” and the line number in an ON ERR statement “well after” the program line that contains the `` statement has been executed. Then the first error condition forces the abandonment of sequential line read, and the line that is designated in the ON ERR statement is executed. Therefore, if you use ``, it is best to terminate the ON ERR “whether an error exists or not”. One DOS (AERCO FD-68) will carry forward a ON ERR condition when a new Basic Program is loaded without a computer reset. This can cause the next program loaded to give you an unpleasant suprise. ON ERR programming can let the programmer do many things that cannot be achieved by any other means. But it is not good programming technique to leave a ON ERR condition dangling. I’ll give a couple of examples that can be modified and used in different ways. First, the cure for the FD-68 programs that may be loaded during a ON ERR condition in a preceeding program. ``` 5 REM ** RESET a ON ERR 10 ON ERR GO TO 9000: STOP 20 STOP : REM **Line to begin your programming. 9000 ON ERR RESET : GO TO 20 ``` Let your auto run line be line 10. The ON ERR changes any existing ON ERR programming to line 9000, and then the STOP forces line 9000 to execute, where the ON ERR is cleared with RESET. Then your first real programming can begin at line 20. The next illustration is more complex. Here we use ON ERR almost as we would use ``. Say you need to present on screen the “status of a data base” contained in a character array “O$()”. A subscript error would occur if O$ were not dimensioned. Then you may want to know the actual Dimension of O$ array. Then you may also want to know the last “cell of O$” that contains data (not empty spaces). We will use ON ERR within counters to do that in the following subroutine. ``` 5 REM ** Use ON ERR to find the Dimension of a CHR$ Array. 10 LET a=500: FOR n=1 TO a: ON ERR GO TO 9000: LET b=LEN o$(n) : NEXT n 20 CLS : STOP : REM **Line to begin your Basic programming. 9000 ON ERR RESET : IF n<2 THEN PRINT "O$ is not Dimensioned." 9005 IF n>2 THEN PRINT "The Dimension of O$ is> "; FLASH 1;"O$(";n-1;")"'' 9010 IF n>1 THEN FOR n=1 TO n-1: ON ERR GO TO 9020: IF O$(n)(1)=" " THEN STOP 9015 NEXT n 9020 ON ERR RESET : IF n=1 THEN PRINT "O$ has no data": STOP 9025 ON ERR RESET : IF n>1 THEN PRINT "The last cell of O$ that has Data is "; FLASH 1;"O$(";n-1;")" 9030 BEEP 3,16: LET n=a: GO TO 20 ``` Each of this routine’s actions to check the status of O$ serves the same purpose as an ``, except that `` cannot be used because it could result in a subscript error. So ON ERR allows us to check the status of a data base “whether the data base exists or not”. It is important to note that at the end of the `` Subroutine, the `` condition is cleared (RESET). Then any subsequent error will be reported as normal with a “report code” at the screen bottom. Lets do one more that is simpler. This time we will check the status of a simple string content (A$). A subscript error will occur if A$ has not been initialized in this example. `<10 PRINT "The Data Base is "; LEN A$;" bytes">`. The ON ERR routine would be: ``` 10 ON ERR GO TO 9000: PRINT "The Data Base is ";LEN a$;" bytes.": ON ERR GO TO 9010: STOP 20 STOP : REM * The next line. 9000 ON ERR RESET : CLS : LET a$="": GO TO 10 9010 ON ERR RESET : GO TO 20 ``` If A$ has not been initialized, the ON ERR trips to line 9000. But if A$ has data the LENgth of A$ is reported and the second ON ERR designates a new line to GO TO if an error exists. Then STOP triggers the GO TO 9010. In either case `` clears the ON ERR programming. It might be worth noting that `` clears the error condition. But, `` is ignored if the error condition has already been cleared. There is no adverse effect if `` is encountered. The follow on programming in the line is executed whether or not the RESET actually reset an error or not. *** ### Notes 1. Line 9005 as printed tests `IF n>2`, and line 9000 tests `IF n<2`. An array dimensioned to a single element raises its subscript error on the second pass of the loop at line 10, so the subroutine is entered with `n=2` and neither test is satisfied — that one case reports neither “not Dimensioned” nor a dimension. `IF n>=2` at 9005 would close the gap. Reproduced as printed, because nothing else in the article establishes the intended form.