Difference between revisions of "Debug.traceback"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Available since:''' Gideros 2011.6<br/>
+
<languages />
=== Description ===
+
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
 +
'''<translate>Class</translate>:''' [[Special:MyLanguage/debug|debug]]<br/>
 +
=== <translate>Description</translate> ===
 
<translate>Frequently, when an error happens, we want more debug information than only the location where the error occurred. At least, we want a traceback, showing the complete stack of calls leading to the error. When pcall returns its error message, it destroys part of the stack (the part that went from it to the error point). Consequently, if we want a traceback, we must build it before pcall returns. To do that, Lua provides the xpcall function. Besides the function to be called, it receives a second argument, an error handler function. In case of errors, Lua calls that error handler before the stack unwinds, so that it can use the debug library to gather any extra information it wants about the error. Two common error handlers are debug.debug, which gives you a Lua prompt so that you can inspect by yourself what was going on when the error happened (later we will see more about that, when we discuss the debug library); and debug.traceback, which builds an extended error message with a traceback. The latter is the function that the stand-alone interpreter uses to build its error messages. You also can call debug.traceback at any moment to get a traceback of the current execution:</translate>
 
<translate>Frequently, when an error happens, we want more debug information than only the location where the error occurred. At least, we want a traceback, showing the complete stack of calls leading to the error. When pcall returns its error message, it destroys part of the stack (the part that went from it to the error point). Consequently, if we want a traceback, we must build it before pcall returns. To do that, Lua provides the xpcall function. Besides the function to be called, it receives a second argument, an error handler function. In case of errors, Lua calls that error handler before the stack unwinds, so that it can use the debug library to gather any extra information it wants about the error. Two common error handlers are debug.debug, which gives you a Lua prompt so that you can inspect by yourself what was going on when the error happened (later we will see more about that, when we discuss the debug library); and debug.traceback, which builds an extended error message with a traceback. The latter is the function that the stand-alone interpreter uses to build its error messages. You also can call debug.traceback at any moment to get a traceback of the current execution:</translate>
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(string) = debug.traceback(message,level)
 
(string) = debug.traceback(message,level)
</source>
+
</syntaxhighlight>
=== Parameters ===
+
=== <translate>Parameters</translate> ===
 
'''message''': (string) <translate>message to debug</translate> '''optional'''<br/>
 
'''message''': (string) <translate>message to debug</translate> '''optional'''<br/>
 
'''level''': (number) <translate>stack level</translate> '''optional'''<br/>
 
'''level''': (number) <translate>stack level</translate> '''optional'''<br/>
=== Return values ===
+
=== <translate>Return values</translate> ===
'''Returns''' (string) <translate>debug traceback</translate><br/>
+
'''<translate>Returns</translate>''' (string) <translate>debug traceback</translate><br/>
 +
 
 +
{{Debug}}

Latest revision as of 14:27, 13 July 2023


Available since: Gideros 2011.6
Class: debug

Description

Frequently, when an error happens, we want more debug information than only the location where the error occurred. At least, we want a traceback, showing the complete stack of calls leading to the error. When pcall returns its error message, it destroys part of the stack (the part that went from it to the error point). Consequently, if we want a traceback, we must build it before pcall returns. To do that, Lua provides the xpcall function. Besides the function to be called, it receives a second argument, an error handler function. In case of errors, Lua calls that error handler before the stack unwinds, so that it can use the debug library to gather any extra information it wants about the error. Two common error handlers are debug.debug, which gives you a Lua prompt so that you can inspect by yourself what was going on when the error happened (later we will see more about that, when we discuss the debug library); and debug.traceback, which builds an extended error message with a traceback. The latter is the function that the stand-alone interpreter uses to build its error messages. You also can call debug.traceback at any moment to get a traceback of the current execution:

(string) = debug.traceback(message,level)

Parameters

message: (string) message to debug optional
level: (number) stack level optional

Return values

Returns (string) debug traceback