Whenever a primitive error occurs in MzScheme, an exception is raised. The value that is passed to the current exception handler is always an instance of the exn structure type. Every exn structure value has a message field that is a string, the primitive error message. The default exception handler recognizes exception values with the exn? predicate and passes the error message to the current error display handler (see section 3.12).
Primitive errors do not create immediate instances of the exn structure type. Instead, an instance from a hierarchy of subtypes of exn is instantiated. The subtype more precisely identifies the error that occurred and may contain additional information about the error. The table below defines the type hierarchy that is used by primitive errors and matches each subtype with the primitive errors that instantiate it.
In this table, each bulleted line is a separate structure type. A type is nested under another when it is a subtype. The full name of the structure type (as used by predicates and selectors in the global environment) is built by combining the full name of the immediate supertype with ``:'' and the subtype name.
For example, applying a procedure to the wrong number of arguments raises an exception as an instance of exn:application:arity. An exception handler can test for this kind of excpetion using the global exn:application:arity? predicate. Given such an exception, the (incorrect) number of arguments provided is obtained from the exception with exn:application-value, while exn:application:arity-expected accesses the actual arity of the procedure.
exn : not instantiated directly fields: message -- error message (type: string) debug-info -- value returned by the current debug info handler (called just after the exception and before raise) (type: anything)
user : raised by calling error
syntax : all syntax errors, but not read errors fields: expr -- illegal expression (type: S-expression)
variable : unbound identifier at run-time fields: id -- the unbound identifier (type: identifier)
application : not instantiated directly fields: value -- the error-specific inappropriate value (type: error-specific)
non-procedure : application of a non-procedure
arity : application with the wrong number of arguments fields: expected -- the correct procedure arity as returned by arity (type: arity)
type : wrong argument type to a primitive, not including illegal zero or negative numbers to some math primitives fields: expected -- name of the expected type (type: symbol)
range : not instantiated directly
bounds : not instantiated directly fields: min -- minimum legal index (type: integer) max -- maximum legal index (type: integer)
vector : illegal vector index; raised by vector-ref, vector-set!
string : illegal string index; raised by string-ref, string-set!, substring
struct : illegal struct index; raised by struct-ref
list : illegal list index; raised by list-ref, list-tail
list-sizes : mismatched list sizes; raised by map, for-each
math : not instantiated directly
zero : divide by zero, etc.; raised by /, quotient, remainder, modulo, angle; application-value is always zero
infinity : infinity overflows; never raised by MzScheme
negative : illegal negative input (e.g. sqrt); never raised by MzScheme
radix : unsupported radix (positive fixnum); raised by number->string
mode-conflict : incompatible mode flags; raised by open-output-file, call-with-output-file, with-output-to-file fields: filename -- filename being opened (type: string)
fprintf : not instantiated directly
extra-arguments : arguments without corresponding formatting tags; application-value is a list of extra arguments
no-argument : formatting tags without corresponding arguments; application-value is the tag string
else : fall-through in cond or case (when MzScheme option is enabled)
struct : not instantiated directly
super-type : the supertype expression in define-struct returned something not a structure type value fields: value -- the given supertype value (type: anything except structure type)
object : not instantiated directly
super-type : the superclass expression in class* returned a non-class fields: value -- the given superclass value (type: anything except class)
class : the object was not in the class; raised by uq-ivar, generic procedure fields: object -- the object (type: object) class -- the class (type: class)
inherit : inherited ivar not found; raised by class* fields: ivar -- instance variable name (type: identifier)
class-ivar : instance variable not found; raised by make-generic fields: class -- the class (type: class) ivar -- instance variable name (type: identifier)
ivar : instance variable not found; raised by uq-ivar fields: object -- the object (type: object) class -- the class; #f indicates unspecified (type: class or #f) ivar -- instance variable name (type: identifier)
private-class : cannot instantiate or derive from this primitive class; raised by make-object, class* fields: class -- the class (type: class)
init : not instantiated directly fields: object -- the object (type: object) class -- the class in which the error occurred (type: class)
multiple : the superclass intialization proc (e.g., super-init) called twice for the class
never : the superclass intialization proc (e.g., super-init) never called for the class
unit : not instantiated directly
non-unit : attempt to link a non-unit; raised by compound-unit fields: value -- non-unit value (type: anything)
arity : attempt to link a unit with the wrong number of imported variables; raised by compound-unit fields: unit -- unit (type: unit)
import : cannot find variable to import; raised by compound-unit fields: unit -- importing unit (type: unit) tag -- import variable tag (type: identifier) name -- inport variable name (type: identifier)
export : cannot find variable to export for compound unit; raised by compound-unit fields: tag -- import variable tag (type: identifier) name -- inport variable name (type: identifier)
read : not instantiated directly fields: port -- port being read (type: port)
paren : unexpected close paren
number : bad number syntax fields: input -- input number string (type: string)
char : bad character constant fields: input -- input character string without #
(type: string)
eof : unexpected end of file fields: expected -- expected input (type: string)
dot : dot at top-level or illegal use of dot; e.g., ( . 1)
unsupported : unsupported # tag fields: input -- input string without # (type: string)
vector-length : illegal vector size in vector constant fields: input -- vector length string (type: string)
compiled : illegal MzScheme compiled code
graph : bad graph syntax
i/o : not instantiated directly
filesystem : not instantiated directly fields: pathname -- pathname (type: string)
filename : bad filename or file not found; raised by all file procedures that take a pathname
directory : directory not found; raised by current-directory, directory-list, load-with-cd
username : bad username (Unix only); raised by all file procedures that take a pathname
file-exists : cannot overwrite file; raised by open-output-file
port-closed : attempt to operate on a closed port; raised by read, write, display, char-ready? fields: port -- port for attempted operation (type: port)
user-port : user-defined input port returned a non-character from the character-getting procedure fields: port -- user-defined input port (type: port)
misc : low-level errors
unsupported : unsupported feature
user-break : user break poll handler returned a true value
out-of-memory : out of memory
defmacro : macro handler is not a procedure fields: value -- the given macro handler (type: anything except a procedure)
expansion-time : local-expansion-time-value called at run-time
constant : attempt to change a constant global; raised by set!, define, undefine fields: id -- constant identifier (type: identifier)
continuation : attempt to cross a continuation boundary or apply another thread's continuation
hash-table : failed hash table lookup fields: key -- key for failed lookup (type: anything)
regexp : all regular expression errors
process : error executing an operating system process
dynamic-extension : not instantiated directly fields: name -- dynamic extension pathname (type: string)
open : cannot open dynamic extension
version : dynamic extension is wrong version
initialize : cannot initialize dynamic extension
Primitive procedures that accept a fixed-arity procedure argument (e.g., call-with-input-file, call/cc) check the argument's arity immediately, raising exn:application:arity if the arity is incorrect.