16.  Error Functions  

(unix-errval expression)

Normally, a Scheme error is signaled by the UNIX extension whenever a UNIX system call or library function invoked by any of the above primitives fails. The macro unix-errval allows an application to handle an error condition in a specific way without the need to redefine the standard error handler of Elk.

unix-errval evaluates the specified expression and returns the result of the evaluation. If, during evaluation of the expression, an error is signaled due to failure of a UNIX function, the corresponding primitive procedure returns a unique error object instead of performing normal error handling.

For example, evaluating the expression

(unix-close 1000)    ; close a bad file descriptor
would invoke the standard Scheme error handler in the normal way, whereas evaluating
(unix-errval (unix-close 1000))
would return an error object to allow the application to handle the error locally. Note that evaluation of the enclosing expression is not interrupted when an error is signaled, i.e. the expression
(unix-errval (begin (unix-close 1000) 5))
would return the integer 5.

(unix-error? obj)

This procedure returns #t if obj is the error object, #f otherwise. unix-error? is typically used to check whether a primitive invoked under control of unix-errval has signaled an error.


Returns the UNIX errno set by the last system call that has failed. Error codes are represented as symbols corresponding to the names of the standard UNIX error numbers with letters converted to lower case, i.e. enomem, ebadf, etc. The exact set of error codes that can be returned is platform-dependent.

The value returned by unix-errno is not reset when a UNIX system call executes successfully. However, value of unix-errno is also affected by functions from the Elk kernel (such as open-input-file) and possibly other extensions that make use of system calls.

(unix-perror string)

unix-perror writes string followed by a colon and a short message describing the last UNIX error encountered to the current output port. unix-perror makes use of the ``~E'' format specifier of the format primitive.

Markup created by unroff 1.0,    September 24, 1996,    net@informatik.uni-bremen.de