Next: , Previous: Using Scheme records in C, Up: C interface


7.9 Raising exceptions from C

The following macros raise certain errors, immediately returning to Scheme48. Raising an exception performs all necessary clean-up actions to properly return to Scheme48, including adjusting the stack of protected variables.

— C function: s48_raise_scheme_exception (int type, int nargs, ...)

The base procedure for raising exceptions. Type is the type of exception; it should be one of the S48_EXCEPTION_... constants defined in scheme48.h. Nargs is the number of additional values to be included in the exception; these follow the nargs argument and should all have the type s48_value. Nargs may not be greater than ten. s48_raise_scheme_exception never returns.

— C function: s48_raise_argument_type_error (s48_value arg)
— C function: s48_raise_argument_number_error (s48_value nargs, s48_value min, s48_value max)
— C function: s48_raise_range_error (s48_value value, s48_value min, s48_value max)
— C function: s48_raise_closed_channel_error ()
— C function: s48_raise_os_error (int errno)
— C function: s48_raise_out_of_memory_error ()

Conveniences for raising certain kinds of exceptions. Argument type errors are due to procedures receiving arguments of the incorrect type. Argument number errors are due to the number of arguments being passed to a procedure, nargs, not being between min or max, inclusive. Range errors are similar, but they are intended for larger ranges, not argument numbers. Closed channel errors occur when a channel was operated upon with the expectation that it would not be closed. OS errors originate from the OS, and they are denoted with Unix errno values.

— C macro: void S48_CHECK_BOOLEAN (s48_value object)
— C macro: void S48_CHECK_SYMBOL (s48_value object)
— C macro: void S48_CHECK_PAIR (s48_value object)
— C macro: void S48_CHECK_STRING (s48_value object)
— C macro: void S48_CHECK_INTEGER (s48_value object)
— C macro: void S48_CHECK_CHANNEL (s48_value object)
— C macro: void S48_CHECK_BYTE_VECTOR (s48_value object)
— C macro: void S48_CHECK_RECORD (s48_value object)
— C macro: void S48_CHECK_SHARED_BINDING (s48_value object)

Conveniences for checking argument types. These signal argument type errors with s48_raise_argument_type_error if their argument is not of the type being tested.