namespace DebugUtils function PrintStackTrace(message = invalid as dynamic) #if DEBUG try throw "Handled throw in DebugUtils.PrintStackTrace()" catch error lines = [] if message <> invalid lines.push(`${message}`) end if lines.push(`Stacktrace:`) for i = error.backtrace.count() - 2 to 0 step -1 backtrace = error.backtrace[i] lines.push(` ${backtrace.function} @ ${backtrace.filename}:${backtrace.line_number}`) end for PrintInABox(lines) end try #end if end function function PrintInABox(lines as object) #if DEBUG maxLen = 0 for each line in lines if line.len() > maxLen maxLen = line.len() end if end for out = "╔" + string(maxLen + 2, "═") + "╗" for each line in lines out += `\n` + "║ " + line + string(maxLen - line.len(), " ") + " ║" end for out += `\n` + "╚" + string(maxLen + 2, "═") + "╝" ? out #end if end function end namespace