error, assertion-violation - raise an exception
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme base)) ;R7RS
(error who message irritant1 ...) ;R6RS
(assertion-violation who message irritant1 ...) ;R6RS
(error message irritant1 ...) ;R7RS
These procedures raise an exception.
procedure should be called when an error has occurred, typically
caused by something that has gone wrong in the interaction of the
program with the external world or the user.
procedure should be called when an invalid call to a procedure was
made, either passing an invalid number of arguments, or passing an
argument that it is not specified to handle.
argument should describe the procedure or operation that detected the
argument should describe the exceptional situation. The
should be the arguments to the operation that detected the operation.
The condition object provided with the exception has the following
the condition has condition type
as the value of its field. In that case,
should be the name of the procedure or entity that
detected the exception.
If it is
the condition does not have
The condition has condition type
as the value of its field.
The condition has condition type
and its field has as its value a list of the
Moreover, the condition created by
and the condition created by
has condition type
Raises an exception as if by calling
on a newly allocated implementation-defined object which encapsulates
the information provided by
as well as any
on such objects.
There is no
These procedures do not return.
(define (fac n)
(when (not (integer-valued? n))
(assertion-violation 'fac "non-integral argument" n))
(when (negative? n)
(assertion-violation 'fac "negative argument" n))
(letrec ((loop (lambda (n r)
(if (zero? n)
(loop (- n 1) (* r n))))))
(loop n 1)))
(fac 5) => 120
(fac 4.5) => &assertion exception
(fac -3) => &assertion exception
(define (null-list? l)
(cond ((pair? l) #f)
((null? l) #t)
"null-list?: argument out of domain"
These procedures are used when there is an error in the program.
difference between an error and assertion is that an assertion is
caused by faults internal to the program, i.e. one would be inclined
to say that a program which crashes from an
is buggy, whereas if it crashes from an
then it crashed due to external circumstances.
procedure is absent from R7RS. Code that needs to work on both R6RS and R7RS
can define an
procedure that calls
and moves the
argument into the
Previous to R6RS and R7RS, programs would either contain a deliberate
error and hope that it would be detected and reported, or they would
use SRFI-23. Most Scheme implementations did have some built-in error
reporting mechanism that could be used, but it would be non-portable.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
must be a string or a symbol or
must be a string.
The assertions described above are errors.
Implementations may signal an error, extend the procedure's
domain of definition to include such arguments,
or fail catastrophically.
procedure is absent from R2RS to R5RS. Before R2RS, Scheme had access
function in MacLISP. Programs in the R4RS and R5RS era often used
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Markup created by unroff 1.0sc, March 04, 2023.