Contents Previous Next Subchapters

Trapping O-Matrix Errors Under Program Control
Syntax errortrap
See Also error , help , halt , stop

O-Matrix detects certain errors while compiling or executing, such as invalid data in a file. The errortrap function enables a program written in O-Matrix to translate an O-Matrix error message to something more useful to the person running a particular O-Matrix program.

If trap is not present in the call to errortrap, error trapping is turned off and the normal O-Matrix error dialog is used.

Sets up the function trap as the transfer point if and when an error occurs. If an error occurs after a call of this form, all active function calls are aborted, all active include files are aborted, and the trap function is called with the parameters described below:

The argument topic is a character row vector containing the O-Matrix help topic that corresponds to the help button in the normal error dialog. The argument msg is a character matrix containing the message that the normal dialog would display.

The following is a simple error handler that adds extra information to the error message:
     ExtraInformation = novalue
     function trap(topic, msg) begin
          global ExtraInformation
          print ExtraInformation
          print msg
     errortrap(function trap)
Suppose that the file TEMP.DAT contains the following text
     1 2 3 4
     5 6 ; 8
If you enter the error handler above and then enter
     ExtraInformation = "Reading input data file:"
     read("TEMP.DAT", "int", 2, 4)
O-Matrix will print the following in the Command window
     Reading input data file:

     read: invalid character for int type
     Line 2 File C:\OMWIN\TEMP.DAT
     Executing at or below line 22 in file
     command line
        19      end
        20      errortrap(function trap)
        21      ExtraInformation = "Reading input data file:"
     ->         read("TEMP.DAT", "int", 2, 4)
(the line numbers will be different). You can restore normal error processing by entering: