Amos Professional Manual  Contents  Index

Error Handling


Call ON ERROR without any parameters like that, or force it to go to zero, like this:

X> On Error Goto 0

To get back to your program after ON ERROR has been called, you must use RESUME. Never use GOTO for this purpose.

RESUME
structure: resume the execution of current program after an error trapping routine
Resume
Resume Next
Resume labelname
Resume linenumber

Used on its own, RESUME will jump back to the statement which caused the error and try it again. To return to the instruction immediately after the one that caused the error, use RESUME NEXT. Alternatively, to jump to a specific point in your main program, simply follow RESUME with a reference to a chosen label or a normal line number.

ON ERROR PROC
structure: trap an error using a procedure
On Error Proc name

Errors can also be trapped using a procedure. ON ERROR PROC selects a named procedure which is automatically called if there is an error in the main program. In fact, this is a structured version of the ON ERROR GOTO command. In this case, your procedure must be terminated by an END PROC in the usual way, then return to the main program with an additional call to RESUME, which can be placed just before the final END PROC statement. Here is an example:

E> On Error Proc HELP
    Do
     Input "Type in two numbers";A,B
     Print A;" divided by ";B;" is ";A/B
    Loop
    Rem Error Handler
    Procedure HELP
     Print
     Print "Sorry, you have tried to divide"
     Print "your number by zero."
    Resume Next: Rem Go back to input
   End Proc

When using a procedure to deal with errors, and you want to jump to a particular label, a special marker must be placed inside that procedure. This is achieved with the RESUME LABEL structure.

Back    Next
12.02.02