Difference between revisions of "StackTrace"

From MiniScript Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
 
In [[Mini Micro]] and [[Farmtronics]], the <c>stackTrace</c> method returns a list of program locations that represent the call stack.
 
In [[Mini Micro]] and [[Farmtronics]], the <c>stackTrace</c> method returns a list of program locations that represent the call stack.
  
 +
This may be used in code, at runtime, but more typically it is used on the command line after a program aborts due to an error.
  
 
== Example ==
 
== Example ==

Latest revision as of 03:34, 4 January 2023

In Mini Micro and Farmtronics, the stackTrace method returns a list of program locations that represent the call stack.

This may be used in code, at runtime, but more typically it is used on the command line after a program aborts due to an error.

Example

In this hypothetical example, a program two import modules, gui and events, encounters a error in the gui module that causes the program to break out to the command line. Entering pprint stackTrace at this point produces the following.

]pprint stackTrace
[
    gui.ms line 276,
    (current program) line 152,
    events.ms line 165,
    events.ms line 203,
    (current program) line 323
]

This stackTrace result is interpreted as follows:

  1. The first line in the result is where the error occurred: line 276 of the file gui.ms.
  2. The next line shows where that final call into gui.ms was made, i.e., line 152 of the currently loaded program.
  3. That was called from events.ms line 165...
  4. which in turn was called from line 203 of the same module.
  5. Finally, that initial call into events was made from line 323 of the current program.

In this way, you can see not only where the error occurred, but how the code got there.

See also: Debugging Tips