end-of-file
end-of-file Condition Type
Class Precedence List:
end-of-file, stream-error, error, serious-condition, condition, t
Description:
The type end-of-file consists of error conditions related to read operations that are done on streams that have no more data.
See Also:
stream-error-streamExpanded Reference: end-of-file
Overview
end-of-file is a condition type signaled when a read operation is performed on a stream that has no more data. It is a subtype of stream-error.
Catching end-of-file
(handler-case
(read-char (make-string-input-stream ""))
(end-of-file () :got-eof))
=> :GOT-EOF
Accessing the Stream from the Condition
Since end-of-file inherits from stream-error, you can use stream-error-stream to get the offending stream.
(handler-case
(read (make-string-input-stream ""))
(end-of-file (c)
(streamp (stream-error-stream c))))
=> T
Avoiding end-of-file with eof-error-p
Most read functions accept an eof-error-p argument. When false, the function returns an eof-value instead of signaling the condition.
(read-char (make-string-input-stream "") nil :eof)
=> :EOF
Type Hierarchy
(subtypep 'end-of-file 'stream-error)
=> T
=> T
(subtypep 'end-of-file 'error)
=> T
=> T