Error Handling & Debugging

From Recital Documentation Wiki
Jump to: navigation, search

Error Handling

When an error occurs in a running application, Recital will stop execution, display an error message and create an error.mem file, unless an alternative error handling procedure has been specified.


Error.mem

The error.mem file includes the following information:

  • The Recital Product version, release, platform and compile date information
  • System information, such as maximum file size and maximum process stack
  • Recital License information
  • User and Node names and process ID
  • The error number
  • The error message
  • The program line
  • The program line number
  • A stack trace of the programs and procedures called
  • A list of all active public and private memory variables and classes
  • Status of open tables, indexes and current records.
  • Settings listing as per LIST STATUS


SET ERRORVERSION

The error.mem file will be named error.mem and will be overwritten by subsequent errors unless SET ERRORVERSION is ON. If SET ERRORVERSION is ON, multiple numbered error.mem files are created with the following naming format:

error0001.mem

error0002.mem

error0003.mem


DB_ERRORDIR

The error.mem file(s) will be created in the directory that is current when the error occurs unless the DB_ERRORDIR environment variable. If set, DB_ERRORDIR points to a directory in which the error.mem file(s) will be created.


ON ERROR

Alternative error handling procedures can be specified using the ON ERROR command. When there is an active ON ERROR setting, no error.mem file will be created and program execution willl not be halted. It is now up to ON ERROR error handler to trap the information required in order to trace the error and to take appropriate action based on the error that has occurred.

Note: The SAVE ERROR command allows for the creation of an equivalent of the error.mem file.


Error Information Functions

Several functions are available to give information about errors:


FUNCTION RETURNS
ERRNO() Operating System Error Number
ERROR() Recital 4GL Error Number
MESSAGE() Error Message
MESSAGE(1) Line which caused the error
PROCLINE() Currently executing procedure line number
PROCNAME() Currently executing procedure name


It is important to note that the PROCLINE() and PROCNAME() functions return information about the CURRENTLY executing procedure. If these functions are called from within the error handling procedure, they will give information based on the error handling procedure itself and not the procedure in which the error occurred. They should, therefore, be specified as parameters to the error handler, e.g.


on error do MyErrProc with procname(), procline()


Debugging

In the Recital development environment, the DEBUG command displays a pop-up debugger allowing the specified program to be monitored during execution. The pop-up debugger can also be activated by using the SET STEP command. To debug an entire program, issue SET STEP ON before starting. To debug just a particular section of the program, insert the command into the code. The debugger can be toggled on and off while running your program by means of a hot key procedure, e.g.:


procedure SetStep
// set step to opposite of current value
set step (!(set([step])))
return
 
procedure DefineKey
// set [TAB] as the hot key to call SetStep
on key label tab do SetStep
return


During the debugging process, the program must be running in interpreted mode, not in compiled mode. The DEBUG command will do this automatically. To ensure that the program is running in interpreted mode when using SET STEP ON/OFF, issue the following two commands before starting program execution:

SET COMPILE OFF

SET DEVELOPMENT OFF


When running in interpreted mode, a complete history trace of all commands executed can be generated. This requires the use of the SET HISTORY and SET DOHISTORY commands.


Example

set compile off
set development off
set history on
set dohistory on
set history to file myhis
use demo
edit
set history to
set dohistory off
vi myhis.his