11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Caché</strong> <strong>ObjectScript</strong> Special VariablesIf no valid $HALT is set in the current context or previous contexts, issuing a HALT commandcompletely unwinds the stack and performs an actual program halt.Commonly, a halt trap routine performs some clean-up or reporting processing, and thenissues a HALT command. Note that with $HALT defined, the original HALT commandinvokes the halt trap, but does not perform an actual program halt. For an actual halt to occur,the halt trap routine must contain a second HALT command.A HALT command issued by a halt trap routine is not trapped by that halt trap, but it maybe trapped by a halt trap established at a lower context level. Thus a cascading series of halttraps may be invoked by a single HALT command.Similar processing is performed by the error trap command ZTRAP, and the associated$ZTRAP and $ETRAP special variables.ExamplesThe following example uses $HALT to establish a halt trap:SET $HALT="MyTrap^CleanupRoutine"WRITE !,"the halt trap is: ",$HALTNote that it is the programmer's responsibility to make sure that the specified routine exists.The following example shows how the halt trap routine executes in the context at which$HALT was defined. In this example, $HALT is defined at $ESTACK level 0, HALT isissued at $ESTACK level 1, and the halt trap routine executes at $ESTACK level 0.MainNEW $ESTACKSET $HALT="OnHalt"WRITE !,"Main $ESTACK= ",$ESTACK," $HALT= ",$HALT // 0DO SubAWRITE !,"Returned from SubA" // not executedQUITSubAWRITE !,"SubA $ESTACK= ",$ESTACK," $HALT= ",$HALT // 1HALTWRITE !,"this should never display"QUITOnHaltWRITE !,"OnHalt $ESTACK= ",$ESTACK // 0HALTQUITThe following example is identical to the previous example, except that $HALT is definedat $ESTACK level 1. A HALT command is issued at $ESTACK level 1, and the halt traproutine executes at $ESTACK level 1. The HALT issued by the halt trap routine unwindsthe stack, and, failing to find a $HALT defined at the previous context level, it halts programexecution. Thus, the WRITE command following the DO command is not executed.430 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!