The $STACK function returns strings describing aspects of the execution environment.
The format for the $STACK function is:
$ST[ACK](intexpr[,expr])
The intexpr identifies the M virtual machine stack level (as described by the standard), on which the function is to provide information.
The optional second argument is evaluated as a keyword that specifies a type of information to be returned as follows: "PLACE" for position in the code (for which, GT.M. due to its compiled nature, has no information), "MCODE" for the source code if available, or "ECODE" for the $ECODE value associated with the stack level.
When $STACK has only one argument, values corresponding to available stack levels specify a return value that indicates how the level was created, as follows:
If intexpr is zero (0), the function returns information on how GT.M was invoked.
If intexpr is minus one (-1), the function returns the highest level for which $STACK can return information. Note that, if $ECODE="", $STACK(-1) returns the same value as $STACK.
If intexpr is greater than zero (0) and less than or equal to $STACK (-1), indicates how this level of process stack was created ("DO", "XECUTE", or "$$". "$$" being for an extrinsic function).
If intexpr is greater than $STACK (-1), the function returns an empty string.
For any integer value of "level" between 0 and max (inclusive), the function $STACK(level, type) provides the following information:
Type Information
"MCODE" the line of code that was executed
"PLACE" the address of the above line of code or the symbol at ("@") to indicate code executed from a string value
"ECODE" either an empty string, or the error code(s) that was added at this execution level.