Setting $ZTRAP to Other Actions

The QUIT and HALT commands also serve as useful $ETRAP or $ZTRAP actions.

The QUIT command terminates execution at that invocation level.

Example:

	GTM>ZPRINT ^EP10
	EP10WRITE !,"THIS IS ",$TEXT(+0)
	SET $ECODE="";this affects only $ETRAP
	S $ET="S $EC="""" Q" ;this implicitly stacks $ZTRAP
	;N $ZT S $ZT="QUIT" ;would give a similar result
	DO SUB1
	QUIT
	SUB1WRITE !,"THIS IS SUB1"
	DO SUB2
	WRITE !,"THIS IS SUB1 AFTER THE ERROR WAS ‘IGNORED’"
	QUIT
	SUB2WRITE !,"THIS IS SUB2"
	KILL A
	BADWRITE A
	WRITE !,"THIS IS NOT DISPLAYED"
	QUIT
	
	GTM>DO ^EP10
	
	THIS IS EP10
	THIS IS SUB1
	THIS IS SUB2
	THIS IS SUB1 AFTER THE ERROR WAS ‘IGNORED’
	GTM>
	

This routine sets $ETRAP or $ZTRAP to the QUIT command. When the routine encounters an error at label BAD, GT.M executes the active error handling ISV. The QUIT command terminates execution of SUB2 and transfers execution back to SUB1. The WRITE displays the error message using the $ZSTATUS special variable. Because the default behavior is to QUIT after $ETRAP code completes, this technique is mostly useful with $ETRAP as a place holder to avoid the $ETRAP="" semantics when there is no action to take at the current level. With $ZTRAP, where the default behavior is to resume execution at the beginning the line that triggered the error, the QUIT is more than a placeholder.

The HALT command terminates routine execution and returns control to the DCL level. Setting $ETRAP="HALT" or ZTRAP="HALT" is similar to setting the ISV to the empty string except that the "HALT" code does not pass the error condition code back to VMS. After a HALT, $STATUS always contains one (1).

Example:

	GTM>ZPRINT ^EP11
	EP11WRITE !,"THIS IS ",$TEXT(+0)
	SET $ECODE="";this affects only $ETRAP
	SET $ETRAP="HALT";this implicitly stacks $ZTRAP
	;SET $ZTRAP="HALT";would give a similar result
	KILL A
	BADWRITE !,A
	WRITE !,"THIS IS NOT DISPLAYED"
	QUIT
	
	GTM>DO ^EP11
	
	THIS IS EP11
	
	$WRITE SYS$OUTPUT$STATUS
	%X00000001
	
	
	$