Break on an Error

When $ZTRAP is set to a BREAK command and an error occurs, GT.M puts the process into Direct Mode. The default for $ZTRAP is a BREAK command. When developing a program, $ZTRAP="BREAK" allows you to investigate the cause of the error from Direct Mode. For information on GT.M debugging tools, refer to the "Operating and Debugging in Direct Mode" chapter in this manual.

Example:

	GTM> ZPRINT ^EP1
	EP1 WRITE !,"THIS IS "_$TEXT(+0)
	KILL A
	BAD WRITE A
	WRITE !,"THIS IS NOT DISPLAYED"
	QUIT
	GTM> DO ^EP1
	
	THIS IS EP1 %GTM-E-UNDEF, Undefined local variable: A
	At MUMPS source location BAD^EP1
	GTM> ZSHOW
	BAD^EP1 ($ZTRAP)
	(Direct mode)
	
	+1^GTM$DMOD (Direct mode)
	
	GTM> QUIT
	
	GTM> ZSHOW
	+1^GTM$DMOD (Direct mode)
	(Direct mode)
	GTM>
	

Because by default $ETRAP="" and $ZTRAP="B", this example does not explicitly set either $ETRAP or $ZTRAP. When the routine encounters an error at BAD^EP1, GT.M initiates Direct Mode. The ZSHOW displays the M stack that has, at the bottom, the base Direct Mode frame and, at the top, EP1 with a notation that $ZTRAP has been invoked. The QUIT command at the prompt removes EP1 from the stack.

To prevent a program such as a production image from accessing Direct Mode, assign an action other than "BREAK" to $ETRAP or $ZTRAP. The following sections discuss various alternative values for $ETRAP or $ZTRAP.

In order to prevent inappropriate access to Direct Mode, eliminate all BREAKs from the production code. If the code contains BREAK commands, the commands should be subject to a postconditional flag that is only turned on for debugging. ZBREAK serves as an alternative debugging tool that effects only the current process and lasts only for the duration of an image activation.