Next: , Previous: Debugging Continuations, Up: Operational Features

3.10 Errors

A computer-language implementation designer faces choices of how reflexive to make the implementation in handling exceptions and errors; that is, how much of the error and exception routines should be written in the language itself. The design of a portable implementation is further constrained by the need to have (almost) all errors print meaningful messages, even when the implementation itself is not functioning correctly. Therefore, SCM implements much of its error response code in C.

The following common error and conditions are handled by C code. Those with callback names after them can also be handled by Scheme code (see Interrupts). If the callback identifier is not defined at top level, the default error handler (C code) is invoked. There are many other error messages which are not treated specially.

Wrong type in argument
Wrong type in argument 1
Wrong type in argument 2
Wrong type in argument 3
Wrong type in argument 4
Wrong type in argument 5
Wrong number of args
numerical overflow
Argument out of range
GC is (thrashing)
bus error
segment violation
— Variable: errobj

When SCM encounters a non-fatal error, it aborts evaluation of the current form, prints a message explaining the error, and resumes the top level read-eval-print loop. The value of errobj is the offending object if appropriate. The builtin procedure error does not set errobj.

errno and perror report ANSI C errors encountered during a call to a system or library function.

— Function: errno
— Function: errno n

With no argument returns the current value of the system variable errno. When given an argument, errno sets the system variable errno to n and returns the previous value of errno. (errno 0) will clear outstanding errors. This is recommended after try-load returns #f since this occurs when the file could not be opened.

— Function: perror string

Prints on standard error output the argument string, a colon, followed by a space, the error message corresponding to the current value of errno and a newline. The value returned is unspecified.

warn and error provide a uniform way for Scheme code to signal warnings and errors.

— Function: warn arg1 arg2 arg3 ...

Alias for slib:warn. Outputs an error message containing the arguments. warn is defined in Init5e7.scm.

— Function: error arg1 arg2 arg3 ...

Alias for slib:error. Outputs an error message containing the arguments, aborts evaluation of the current form and resumes the top level read-eval-print loop. Error is defined in Init5e7.scm.

If SCM is built with the ‘CAUTIOUS’ flag, then when an error occurs, a stack trace of certain pending calls are printed as part of the default error response. A (memoized) expression and newline are printed for each partially evaluated combination whose procedure is not builtin. See Memoized Expressions for how to read memoized expressions.

Also as the result of the ‘CAUTIOUS’ flag, both error and user-interrupt (invoked by <C-c>) are defined to print stack traces and conclude by calling breakpoint (see Breakpoints). This allows the user to interract with SCM as with Lisp systems.

— Function: stack-trace

Prints information describing the stack of partially evaluated expressions. stack-trace returns #t if any lines were printed and #f otherwise. See Init5e7.scm for an example of the use of stack-trace.