Next: , Previous: , Up: Operational Features   [Contents][Index]


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.

ARGn

Wrong type in argument

ARG1

Wrong type in argument 1

ARG2

Wrong type in argument 2

ARG3

Wrong type in argument 3

ARG4

Wrong type in argument 4

ARG5

Wrong type in argument 5

WNA

Wrong number of args

OVFLOW

numerical overflow

OUTOFRANGE

Argument out of range

NALLOC

(out-of-storage)

THRASH

GC is (thrashing)

EXIT

(end-of-program)

HUP_SIGNAL

(hang-up)

INT_SIGNAL

(user-interrupt)

FPE_SIGNAL

(arithmetic-error)

BUS_SIGNAL

bus error

SEGV_SIGNAL

segment violation

ALRM_SIGNAL

(alarm-interrupt)

VTALRM_SIGNAL

(virtual-alarm-interrupt)

PROF_SIGNAL

(profile-alarm-interrupt)

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 in SLIB. Outputs an error message containing the arguments. warn is defined in Init5f3.scm.

Function: error arg1 arg2 arg3 …

Alias for slib:error in SLIB. 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 Init5f3.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 in SLIB). 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 Init5f3.scm for an example of the use of stack-trace.


Next: , Previous: , Up: Operational Features   [Contents][Index]