Examples of $STACK()

Example:

    WRITE !,$STACK
    XECUTE "WRITE !,$STACK"
    DO Label
    WRITE !,$$ELabel
    WRITE !,$STACK
    QUIT
    
    Label
    WRITE !,$STACK
    DO DLabel
    QUIT
    
    ELabel()
    QUIT $STACK
    
    DLabel
    WRITE !,$STACK
    QUIT
    

The above example when executed displays the current M stack level. The result of the execution is:

    GTM>0
    1
    1
    2
    1
    0
    

Example for error processing:

    For i=$STACK(-1):-1:1 DO
    . WRITE !,$STACK(i,"PLACE"),":"
    . WRITE $STACK(i,"MCODE")
    . QUIT
    

The above example can be used to display a trace of the code path that led to an error.