GT.M does not detect certain types of errors associated with indirection, the functioning of I/O devices, and program logic until run-time. Also, the compile-as-written feature may leave errors which GT.M reports at run-time when it encounters them in the execution path. At run-time, GT.M reports any error encountered to stderr. The run-time system suspends normal execution of the routine as soon as it detects an error.
GT.M responds to errors differently depending on whether it encounters them in Direct Mode (at the command line) or during normal program execution.
When an executing GT.M image encounters an error:
if Direct Mode is active at the top of the invocation stack, GT.M stays in Direct Mode.
otherwise, if the error comes from a device that has an EXCEPTION, GT.M executes the EXCEPTION string.
otherwise, if $ETRAP'="" GT.M transfers control to the code defined by $ETRAP as if it had been inserted at the point of the error, unless $ECODE'="", in which case it executes a TROLLBACK:$TLEVEL followed by a QUIT:$QUIT "" QUIT.
otherwise, if $ZTRAP'="" GT.M executes $ZTRAP.
otherwise, GT.M performs a QUIT:$QUIT "" QUIT and reissues the error at the new stack level, if no other error traps ($ETRAP or $ZTRAP) are uncovered by decending the stack, GT.M reports the error on the principal device and terminates the image.
After the action, if any, invoked by $ETRAP, $ZTRAP or EXCEPTION:
if the process ends in Direct Mode – as a result either of performing a BREAK in the executed string or of starting in Direct Mode – GT.M reports the error on the principal device.
otherwise, if the executed string contains an unstacked transfer of control, the only implicit behavior is that as long as $ECODE'="" and $ZTRAP'="" an attempt to QUIT from the level of the current error causes that error to be reissued at the new stack level.
otherwise, if $ETRAP'="" GT.M performs a QUIT$QUIT "" QUIT and reissues the error at the new stack level.
otherwise, $ZTRAP must contain code and GT.M retries the line of M on which the error occurred.
When GT.M detects an error in Direct Mode, it reports the error with a message and leaves the process at the GTM> prompt.
GTM>ZW ZW ^_____ %GTM-E-INVCMD, Invalid command keyword encountered GTM>
In Direct Mode, GT.M provides access to the RECALL command. RECALL allows you to retrieve a Direct Mode command line with a minimum of typing. A GT.M line editor allows you to make quick changes or corrections to the command line. For more information on RECALL and the line editor, see Chapter 4: “Operating and Debugging in Direct Mode”.
If GT.M encounters an error outside of code entered in Direct Mode, GT.M executes the $ETRAP or $ZTRAP special variable, if either of them have a length greater than zero, which only one can have at a given point in time.
The $ETRAP and $ZTRAP special variables specifiy an action that GT.M should perform when an error occurs during routine execution. $ETRAP and $ZTRAP can establish one or more error handling "actions".
The environment variable gtm_etrap specifies an initial value of $ETRAP to override the default value of "B" for $ZTRAP as the base level error handler. The gtmprofile script sets gtm_etrap to "Write:(0=$STACK) ""Error occurred: "",$ZStatus,!" which you can customize to suit your needs. For more information, refer to “Processing Errors from Direct Mode and Shell”.