BREAK and error-trapping

ResiDOS contains facilities to detect BREAK and error conditions, and have them handled by your own BASIC program, instead of simply having an error message produced. This allows you to write more professional-looking BASIC programs, which can't be broken in to, and which can cope with expected errors (such as being unable to find a file requested by the user, for example).

You are advised to SAVE your work before running any program with error-trapping facilities, as if you have made a mistake somewhere, much trouble can ensue!


You can prevent the user from BREAKing into your program with the %ONBREAK command. This has two forms; to stop BREAK from being effective, use:

The THEN keyword is optional, and used to make entering the CONTINUE keyword easier on normal keyword-driven BASICs. On single-letter-entry BASICs, there is no need to use it.

To restore the normal operation of BREAK, use:

(You could include the THEN keyword again, but it would be more trouble than it's worth to enter it).

Note that BREAK-trapping prevents the user from stopping the program in any of the following ways:

It does not prevent the user from BREAK-ing in by pressing CAPS SHIFT + 6 in an INPUT LINE statement, so you are advised to use a straightforward INPUT instead.


All other errors (except for "OK", "Program finished" and "STOP statement") can be trapped using the %ONERR command. This takes any of the following forms, allowing you to transfer control to an error routine, or just call a subroutine before continuing with the program after the point where the error occurred:

(Again, the THEN statement is optional.)

Your error-handling routine can use any of the following new functions to determine what the error was. They provide the error number, line and statement respectively:

Additionally, the following command makes the last trapped error occur as normal (as if it had not been trapped):

As an example, here is a program that turns on error trapping, causes an error and lets the error routine output details of the error:

	  10 %ONERR GOTO 9000
	  20 PRINT "Hello"
	  30 PRINT: PRINT f
	  40 PRINT "Never get here"
	8999 STOP
	9000 PRINT "Error code was ";FN ERR()
	9010 PRINT "Error line was ";FN ERL()
	9020 PRINT "Error statement was ";FN ERS()
	9030 PRINT "Now causing error..."
	9040 %REPORT


There is a known flaw in ResiDOS with error-trapping. The error-trapping variables are shared between tasks, rather than being saved with each task individually. This means that changing error-trapping in one task will affect all the others. I hope to resolve this in a new release of the task manager in the near future.

Back to the ResiDOS home page