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 SYS$ERROR. 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 behaviour 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.