How to display or save stack information?
Hello.
For debugging purposes I sometimes need to display stack information to the current device or save it (to a global for example).
There is this snippet offered in documentation:
ClassMethod StackToDisplay()
{
For loop = 0:1:$Stack(-1) {
Write !, "Context level:", loop, ?25, "Context type: ", $Stack(loop)
Write !, ?5, "Current place: ", $Stack(loop, "PLACE")
Write !, ?5, "Current source: ", $Stack(loop, "MCODE")
Write !
}
}
And to save stack to a global there's always an exception method:
ClassMethod StackToGlobal()
{
Set ex = ##class(%Exception.SystemException).%New()
Do ex.StackAsArray(.arr)
Set time = $ZDT($H)
Merge ^StackInfo(time) = arr
}
But I'm interested if someone has a better code (more info) for this purpose? What's your approach to saving stack information?