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.
(out-of-storage)
(end-of-program)
(hang-up)
(user-interrupt)
(arithmetic-error)
(alarm-interrupt)
error does
not set errobj.
errno and perror report ANSI C errors encountered during a
call to a system or library function.
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.
errno and a newline. The value returned is unspecified.
warn and error provide a uniform way for Scheme code to
signal warnings and errors.
warn is defined in
`Init.scm'.
Error is defined
in `Init.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.
stack-trace returns #t if any lines were
printed and #f otherwise. See `Init.scm' for an example of
the use of stack-trace.