Stack traces

Monkey Forums/Monkey Programming/Stack traces

Samah(Posted 2011) [#1]
Mark,
Would it be possible to get the stack trace with Error()?

For example, an optional flag to append the stack trace to the error message:
Error("foo", True)

Or preferably a separate function that grabs the stack trace at that point so you can use it for logging:
Local st$ = StackTrace()
Log("stack trace: " + st)

Being able to return the stack trace as an array would be even better!
Local st:String[] = StackTrace()
For Local i% = 0 Until st.Length
  Print("stack line "+i+": "+st[i]
Next

This would be fantastic for diddy's assertion module.

---

Edit: I just noticed the stackTrace() method in lang.monkey, but it's not exposed. Could you expose it in the next release? Having the ability to return an array from the actual vector would be great too.

Edit 2: I also noticed that Error() does this already, if it's compiled in debug. Regardless, exposing stackTrace() as a string or an array would still be helpful.