Amos Professional Manual  Contents  Index

Error Handling


TRAP
instruction: trap an error
Trap instruction

The TRAP command offers a much sleeker error-trapping service than an ON ERROR GOTO structure, and it is used to detect errors for a particular instruction. The TRAP instruction is used before any normal AMOS Professional instruction with no colon between them, and it disables the error system for the specified instruction. This means that if an error occurs, the program will not be halted, but the number of the error will be reported instead. This number can then be returned by the ERRTRAP function, explained below. Here is an example of trapping a disc access error:

E> Trap Load "File.Abk",10
   If Errtrap : Print "Disc Error!" : End If

TRAP will only detect an error for the instruction that immediately follows, so in the next example the second usage of the LOCATE instruction will cause an error!

E> Trap Locate -1,-1 : Locate -1,-1

ERRTRAP
function: return an error code number after a TRAP
number=Errtrap

This function is used to return the error status after a previous TRAP command. If no error has been detected, a zero is returned, otherwise the appropriate error number is given. The related error message can then be returned using the ERR$ function, explained next.

ERR$
function: return an error message string
text$=Err$(error number)

This simple function returns an error message string. If the error number is out of range, then an empty string will be given. ERR$ will return error messages as long as they are loaded in memory, but messages will not be returned from a compiled program, or if the Editor has been KILLed.

Back    Next
12.02.04