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.

You then use the SET command to assign a different value to the new copy of $ETRAP. Inthis way, you can establish new $ETRAP error-handling commands for the current context.You can also clear $ETRAP by setting it to the null string. <strong>Caché</strong> then executes no $ETRAPcommands at the context level in the event of an error.When a QUIT command causes the current context to be exited, <strong>Caché</strong> restores the old, savedvalue of $ETRAP.ExampleThe following example demonstrates how the value of $ETRAP is carried forward into newcontexts and how you can invoke $ETRAP error-handling commands again in each contextafter an error occurs. The $ETRAP commands in this example make no attempt to dismissthe error. Rather, control by default is passed back to $ETRAP error-handling commands ateach previous context level.The sample code is as follows:ETRNEW $ETRAPSET $ETRAP="WRITE !,""$ETRAP invoked at Context Level "",$STACK"; Initiate an XECUTE context that initiates a DO contextXECUTE "DO A"QUIT; Initiate a user-defined function contextASET A=$$BQUIT; A User-defined function that generates an errorB()QUIT 1A sample session using this code might run as follows:>DO ^ETR$ETRAP invoked at context level 4$ETRAP invoked at context level 3$ETRAP invoked at context level 2$ETRAP invoked at context level 1NotesUse NEW Before Setting $ETRAP to a New Value$ETRAPIf you assign a new value to $ETRAP in a context without first creating a new copy of$ETRAP with the NEW command, <strong>Caché</strong> establishes that new value as the value of $ETRAPnot only for the current context but also for all previous contexts. Therefore, <strong>InterSystems</strong>strongly recommends that you create a new copy of $ETRAP with the NEW commandbefore it is set with a new value.<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 427

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

Saved successfully!

Ooh no, something went wrong!