Input/Output Errors

When GT.M encounters an error in the operation of an I/O device, GT.M executes the EXCEPTION deviceparameter for the OPEN/USE/CLOSE commands. An EXCEPTION deviceparameter specifies an action to take when an error occurs in the operation of an I/O device. The form of the EXCEPTION action is subject to the gtm_ztrap_form setting described for $ZTRAP, except that there is never any implicit popping with EXCEPTION actions. If a device has no current EXCEPTION, GT.M uses $ETRAP or $ZTRAP to handle an error from that device.

GT.M provides the option to:

An EXCEPTION based on an error for the device applies only to that device, and provides a specific error handler for a specific I/O device.

The CTRAP deviceparameter for USE establishes a set of trap characters for terminal input. When GT.M encounters an input character in that set, GT.M executes the EXCEPTION deviceparamenter, or, $ETRAP or $ZTRAP if the device has no current EXCEPTION.

Example:

	GTM>ZPRINT ^EP12
	EP12WRITE !,"THIS IS ",$TEXT(+0)
	SET $ECODE="";this only affects $ETRAP
	SET $ETRAP="GOTO ET"
	;N $ZT S $ZT="W !,"CANa??T TAKE RECIPROCAL OF 0"",*7"
	USE $P:(EXCEPTION="D BYE":CTRAP=$C(3))
	WRITE !,"TYPE <CTRL-C> TO STOP"
	LOOPFOR DO
	. READ !,"TYPE A NUMBER: ",X
	. WRITE ?20,"HAS RECIPROCAL OF: ",1/X
	. QUIT
	ET. WRITE !,"CANa??T TAKE RECIRPOCAL OF 0",*7
	. SET $ECODE=""
	QUIT
	BYEWRITE !,"YOU TYPED <CTRL-C> YOU MUST BE DONE!"
	USE $P:(EXCEPTION="":CTRAP="")
	WRITE !,"$ZSTATUS=",$ZSTATUS
	ZGOTO 1
	GTM>DO ^EP12
	THIS IS EP12
	TYPE <CTRL-C> TO STOP
	TYPE A NUMBER: 1 HAS RECIPROCAL OF: 1
	TYPE A NUMBER: 2 HAS RECIRPOCAL OF: .5
	TYPE A NUMBER: 3 HAS RECIPROCAL OF: .33333333333333
	TYPE A NUMBER: 4 HAS RECIPROCAL OF: .25
	TYPE A NUMBER: HAS RECIPROCAL OF:
	CANa??T TAKE RECIPROCAL OF 0
	TYPE A NUMBER:
	YOU TYPED <CTRL-C> YOU MUST BE DONE!
	$ZSTATUS=150372498,LOOP+1^EP12,%GTM-E-CTRAP,Character trap $C(3) encountered
	GTM>
	

This routine prompts the user to enter a number at the terminal. If the user enters a zero, GT.M encounters an error and executes $ETRAP (or $ZTRAP). The action specified reports the error and returns to prompt the user to enter a number. With $ZTRAP, this is very straightforward. With $ETRAP, some care is required to get the code to resume at the proper place. The CTRAP deviceparameter establishes <CTRL-C> as a trap character. When GT.M encounters a <CTRL-C>, GT.M executes the EXCEPTION string whcih transfers control to the label BYE. At the label BYE, the routine terminates execution with an error message. Using the EXCEPTION deviceparameter with CTRAP generally simplifies $ETRAP or $ZTRAP handling.

$ZSTATUS allows the routine to find out which trap character GT.M encountered. When a routine has several character traps set, $ZSTATUS provides useful information for identifying which character triggered the trap, and thereby allows a custom response to a specific input.