Next: , Previous: Value Historyx, Up: Using Guile Interactively

3.4.3 Error Handling

When code being evaluated from the REPL hits an error, Guile remembers the execution context where the error occurred and can give you three levels of information about what the error was and exactly where it occurred.

By default, Guile displays only the first level, which is the most immediate information about where and why the error occurred, for example:

     (make-string (* 4 (+ 3 #\s)) #\space)
     standard input:2:19: In procedure + in expression (+ 3 #\s):
     standard input:2:19: Wrong type argument: #\s
     ABORT: (wrong-type-arg)
     Type "(backtrace)" to get more information
     or "(debug)" to enter the debugger.

However, as the message above says, you can obtain more information about the context of the error by typing (backtrace) or (debug).

(backtrace) displays the Scheme call stack at the point where the error occurred:

     In standard input:
        2: 0* [make-string ...
        2: 1*  [* 4 ...
        2: 2*   [+ 3 #\s]
     Type "(debug-enable 'backtrace)" if you would like a backtrace
     automatically if an error occurs in the future.

In a more complex scenario than this one, this can be extremely useful for understanding where and why the error occurred. You can make Guile show the backtrace automatically by adding (debug-enable 'backtrace) to your .guile.

(debug) takes you into Guile's interactive debugger, which provides commands that allow you to

The interactive debugger is documented further in the following section.