When AMOS Professional encounters an error in your programs, or if you attempt the impossible, automatic assistance is offered in the form of error messages displayed in the information line. If this happens while you are programming, you can try to correct the mistake immediately. If the problem is found when you try to test or run a program, AMOS Professional will take you to the offending line as soon as you edit.
Trapping errors
Routines can be set up in advance for handling errors inside an AMOS Professional program, so
that when a mistake is spotted, error trapping swings into action. This process is triggered by the
following command:
ON ERROR
structure: trap an error within a Basic program
On Error Goto label
By this method, when an error occurs in your Basic program, a jump is made to whatever label has been defined. This label acts as the starting point for your own error correction routine, and after the mistake has been corrected you can return to your main program without the need to go via the editor window. Try this simple routine:
E> Do Input "Type in two numbers";A,B Print A;" divided by ";B;" is ";A/B Loop
This will work perfectly until you try to enter a value of zero for B and it is discovered that division by zero is impossible. Such unforeseen problems can be catered for by setting an error trap like this:
E> On Error Goto HELP AGAIN: Do Input "Type in two numbers";A,B Print A;" divided by ";B;" is ";A/B Loop Rem Error Handler HELP: Print Print "Sorry, you have tried to divide" Print "your number by zero." Resume AGAIN : Rem Go back to input
If you are unfortunate enough to write an error inside your own error trapping routine, AMOS Professional will grind to a halt! There are two ways to deliberately disable ON ERROR GOTO.
X> On Error : Rem disable error trap