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 VariablesWhen an error occurs, this format unwinds the call stack and transfers control to the specifiederror trap handler.You can choose to leave the call stack as it is after the error has occurred. To do so, place anasterisk (*) before location. This form is not valid for use within procedures. It can only beused in subroutines that are not procedures, as in this example:MainSET $ZTRAP="*OnError"WRITE !,"$ZTRAP set to: ",$ZTRAP// program codeOnError// Error handling codeQUITThis format simply causes a GOTO to the tag specified in $ZTRAP; $STACK and$ESTACK are unchanged. The context frame of the $ZTRAP error handling routine is thesame as the context frame where the error occurred. Upon completion of the $ZTRAP errorhandling routine, <strong>Caché</strong> unwinds the stack to the previous context level. This form of $ZTRAPis especially useful for analyzing unexpected errors.Note that the asterisk sets a $ZTRAP option; it is not part of the location. For this reason,this asterisk does not display when performing a WRITE or ZZDUMP on $ZTRAP.The error handlers ^%ETN and ^%ET always behave as if they were preceded by an asterisk(*).To disable error trapping, set $ZTRAP to the null string (""). This clears any error trap setat the current DO stack level.When you set an error handler using $ZTRAP, this handler takes precedence over anyexisting $ETRAP error handler. <strong>Caché</strong> implicitly performs a NEW $ETRAP command andsets $ETRAP to the null string ("").Note:Use of $ZTRAP from the <strong>Caché</strong> Terminal prompt is limited to the current line ofcode. The SET $ZTRAP command and the command generating the error must bein the same line of code. <strong>Caché</strong> Terminal restores $ZTRAP to the system default atthe beginning of each command line.ExamplesThe following example sets $ZTRAP to the OnError routine in this program. It then callsSubA in which an error occurs (attempting to divide a number by 0). When the error occurs,<strong>Caché</strong> calls the OnError routine specified in $ZTRAP. OnError is invoked at the contextlevel at which $ZTRAP was set. Because OnError is at the same context level as Main,execution does not return to Main.496 <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!