1 ;;;; SBCL-specific parts of the condition system, i.e. parts which
2 ;;;; don't duplicate/clobber functionality already provided by the
3 ;;;; cross-compilation host Common Lisp
5 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
14 (in-package "SB!KERNEL")
16 ;;; a utility for SIGNAL, ERROR, CERROR, WARN, COMPILER-NOTIFY and
17 ;;; INVOKE-DEBUGGER: Parse the hairy argument conventions into a
18 ;;; single argument that's directly usable by all the other routines.
19 (defun coerce-to-condition (datum arguments default-type fun-name
)
20 (declare (explicit-check))
21 (cond ((typep datum
'condition
)
22 (when (and arguments
(not (eq fun-name
'cerror
)))
23 (cerror "Ignore the additional arguments."
27 :format-control
"You may not supply additional arguments ~
28 when giving ~S to ~S."
29 :format-arguments
(list datum fun-name
)))
31 ((or (stringp datum
) (functionp datum
))
32 (make-condition default-type
34 :format-arguments arguments
))
36 (apply #'make-condition datum arguments
))))
38 (define-condition layout-invalid
(type-error)
41 (lambda (condition stream
)
43 "~@<invalid structure layout: ~
44 ~2I~_A test for class ~4I~_~S ~
45 ~2I~_was passed the obsolete instance ~4I~_~S~:>"
46 (classoid-proper-name (type-error-expected-type condition
))
47 (type-error-datum condition
)))))
49 (define-condition case-failure
(type-error)
50 ((name :reader case-failure-name
:initarg
:name
)
51 (possibilities :reader case-failure-possibilities
:initarg
:possibilities
))
53 (lambda (condition stream
)
54 (let ((*print-escape
* t
))
55 (format stream
"~@<~S fell through ~S expression.~@[ ~
56 ~:_Wanted one of (~/pprint-fill/).~]~:>"
57 (type-error-datum condition
)
58 (case-failure-name condition
)
59 (case-failure-possibilities condition
))))))
61 (define-condition compiled-program-error
(program-error)
62 ((message :initarg
:message
:reader program-error-message
)
63 (source :initarg
:source
:reader program-error-source
))
64 (:report
(lambda (condition stream
)
65 (format stream
"Execution of a form compiled with errors.~%~
67 Compile-time error:~% ~A"
68 (program-error-source condition
)
69 (program-error-message condition
)))))
71 (define-condition interpreted-program-error
72 (program-error encapsulated-condition
)
73 ;; Unlike COMPILED-PROGRAM-ERROR, we don't need to dump these, so
74 ;; storing the original condition and form is OK.
75 ((form :initarg
:form
:reader program-error-form
))
76 (:report
(lambda (condition stream
)
77 (format stream
"~&Evaluation of~% ~S~%~
79 (program-error-form condition
)
80 (encapsulated-condition condition
)))))
82 (define-condition simple-control-error
(simple-condition control-error
) ())
83 (define-condition simple-file-error
(simple-condition file-error
) ())
84 (define-condition simple-program-error
(simple-condition program-error
) ())
85 (define-condition simple-stream-error
(simple-condition stream-error
) ())
86 (define-condition simple-parse-error
(simple-condition parse-error
) ())
88 (define-condition character-coding-error
(error)
89 ((external-format :initarg
:external-format
:reader character-coding-error-external-format
)))
90 (define-condition character-encoding-error
(character-coding-error)
91 ((code :initarg
:code
:reader character-encoding-error-code
)))
92 (define-condition character-decoding-error
(character-coding-error)
93 ((octets :initarg
:octets
:reader character-decoding-error-octets
)))
94 (define-condition stream-encoding-error
(stream-error character-encoding-error
)
98 (let ((stream (stream-error-stream c
))
99 (code (character-encoding-error-code c
)))
100 (format s
"~@<~S stream encoding error on ~S: ~2I~_~
101 the character with code ~D cannot be encoded.~@:>"
102 (character-coding-error-external-format c
)
105 (define-condition stream-decoding-error
(stream-error character-decoding-error
)
109 (let ((stream (stream-error-stream c
))
110 (octets (character-decoding-error-octets c
)))
111 (format s
"~@<~S stream decoding error on ~S: ~2I~_~
112 the octet sequence ~S cannot be decoded.~@:>"
113 (character-coding-error-external-format c
)
117 (define-condition c-string-encoding-error
(character-encoding-error)
121 (format s
"~@<~S c-string encoding error: ~2I~_~
122 the character with code ~D cannot be encoded.~@:>"
123 (character-coding-error-external-format c
)
124 (character-encoding-error-code c
)))))
126 (define-condition c-string-decoding-error
(character-decoding-error)
130 (format s
"~@<~S c-string decoding error: ~2I~_~
131 the octet sequence ~S cannot be decoded.~@:>"
132 (character-coding-error-external-format c
)
133 (character-decoding-error-octets c
)))))
135 (define-condition control-stack-exhausted
(storage-condition)
138 (lambda (condition stream
)
139 (declare (ignore condition
))
141 ;; no pretty-printing, because that would use a lot of stack.
142 "Control stack exhausted (no more space for function call frames).
143 This is probably due to heavily nested or infinitely recursive function
144 calls, or a tail call that SBCL cannot or has not optimized away.
146 PROCEED WITH CAUTION."))))
148 (define-condition binding-stack-exhausted
(storage-condition)
151 (lambda (condition stream
)
152 (declare (ignore condition
))
154 ;; no pretty-printing, because that would use a lot of stack.
155 "Binding stack exhausted.
157 PROCEED WITH CAUTION."))))
159 (define-condition alien-stack-exhausted
(storage-condition)
162 (lambda (condition stream
)
163 (declare (ignore condition
))
165 ;; no pretty-printing, because that would use a lot of stack.
166 "Alien stack exhausted.
168 PROCEED WITH CAUTION."))))
170 (define-condition heap-exhausted-error
(storage-condition)
173 (lambda (condition stream
)
174 (declare (ignore condition
))
175 (declare (special *heap-exhausted-error-available-bytes
*
176 *heap-exhausted-error-requested-bytes
*))
177 ;; See comments in interr.lisp -- there is a method to this madness.
178 (if (and (boundp '*heap-exhausted-error-available-bytes
*)
179 (boundp '*heap-exhausted-error-requested-bytes
*))
181 ;; no pretty-printing, because that will use a lot of heap.
182 "Heap exhausted (no more space for allocation).
183 ~D bytes available, ~D requested.
185 PROCEED WITH CAUTION."
186 *heap-exhausted-error-available-bytes
*
187 *heap-exhausted-error-requested-bytes
*)
189 "A ~S condition without bindings for heap statistics. (If
190 you did not expect to see this message, please report it."
191 'heap-exhausted-error
)))))
193 (define-condition system-condition
(condition)
194 ((address :initarg
:address
:reader system-condition-address
:initform nil
)
195 (context :initarg
:context
:reader system-condition-context
:initform nil
)))
197 (define-condition memory-fault-error
(system-condition error
) ()
199 (lambda (condition stream
)
200 (format stream
"Unhandled memory fault at #x~X."
201 (system-condition-address condition
)))))
203 (define-condition breakpoint-error
(system-condition error
) ()
205 (lambda (condition stream
)
206 (format stream
"Unhandled breakpoint/trap at #x~X."
207 (system-condition-address condition
)))))
209 (define-condition interactive-interrupt
(system-condition serious-condition
) ()
211 (lambda (condition stream
)
212 (format stream
"Interactive interrupt at #x~X."
213 (system-condition-address condition
)))))