1 obj@(Root traits) notABoolean
2 [error: obj printString ; ' is not a Boolean.'].
4 obj@(Root traits) badTypeError
5 [error: obj printString ; ' is not the right type (probably passed a primitive something other than a small integer).'].
7 conditions define: #SlotError &parents: {Error} &slots: {#object. #slotName}.
8 "Errors related to slot manipulations."
10 conditions define: #SlotNotFound &parents: {SlotError}.
12 obj@(Root traits) slotNotFoundNamed: name
13 [(SlotNotFound new `>> [object := obj. slotName := name. ]) signal].
15 snf@(SlotNotFound traits) describeOn: out
17 out ; 'The object ' ; snf object printString ;
18 ' does not have a slot named ' ; snf slotName printString ; '.\n'
21 conditions define: #SlotTypeError &parents: {SlotError} &slots: {#type}.
22 "Results from attempting to assign a value to a slot that is incompatible with
23 a specified type for the slot."
25 obj@(Root traits) cannotAccept: value in: slotName
26 [(SlotTypeError new `>> [object := obj. slotName := slotName. type := value. ]) signal].
28 conditions define: #RebindError &parents: {SlotError}.
30 cond@(RebindError traits) describeOn: out
32 out ; 'The object ' ; cond object printString ;
33 ' has already bound a slot named ' ; cond slotName printString ; '.\n'
36 obj@(Root traits) rebindOf: name
37 [(RebindError new `>> [object := obj. slotName := name. ]) signal].
39 conditions define: #ProtocolError &parents: {Error}.
40 "A ProtocolError is an Error from not complying with an object's reuse protocol."
42 conditions define: #LexicalContextExpired &parents: {ProtocolError} &slots: {#method. #lexicalContext}.
44 method@(Method traits) mayNotReturnTo: lexicalContext
45 [(LexicalContextExpired new `>> [method := method. lexicalContext := lexicalContext. ]) signal].
47 lce@(LexicalContextExpired traits) describeOn: out
49 out ; 'The method ' ; lce method printString ; ' attempted to access an expired lexical context.\n'
52 conditions define: #WrongInputs &parents: {ProtocolError} &slots: {#method. #arguments.}.
53 "A WrongInputs is a ProtocolError signaled when the wrong number of arguments are applied to a Method."
55 args wrongInputsTo: method@(Method traits)
56 [(WrongInputs new `>> [method := method. arguments := args. ]) signal].
58 wi@(WrongInputs traits) describeOn: out
60 out ; 'The arguments:\n' ; wi arguments printString ;
61 '\ndo not apply to:\n' ; wi method printString ;
62 '\nwhich has an arity of: ' ; wi method arity printString ; '\n'
65 conditions define: #Message &parents: {Cloneable} &slots: {#selector. #arguments. #optionals -> {}}.
66 "A Message describes a message-send at runtime, and usually only exists for
69 m@(Message traits) sending: selector to: args &optionals
71 optionals `defaultsTo: #{}.
72 m cloneSettingSlots: #{#selector. #arguments. #optionals}
73 to: {selector. args. optionals}
76 m@(Message traits) send
77 "Try to send the message."
78 [m selector sendTo: m arguments &optionals: m optionals].
80 m@(Message traits) dispatch
81 "Aliases send, so it performs a method dispatch."
84 conditions define: #MethodNotFound &parents: {ProtocolError} &slots: {#message -> Message}.
86 "A MethodNotFound is a ProtocolError signaled when dispatch fails."
88 selector@(Symbol traits) notFoundOn: arguments &optionals
89 "Query the arguments for an abnormal handler before signalling MethodNotFound."
91 message ::= Message sending: selector to: arguments &optionals: optionals.
92 arguments doWithIndex:
93 [| :arg :index | (arg didNotUnderstand: message at: index) ifNotNilDo:
94 [| :result | ^ result do]].
95 (MethodNotFound new `>> [message := message. ]) signal
98 x@(Root traits) didNotUnderstand: message at: index
99 "This should return a Method which is deemed suitable for responding to the
101 By default, do nothing and answer Nil, signalling that it was not handled."
104 mnf@(MethodNotFound traits) describeOn: out
106 message ::= mnf message.
107 out ; 'The method ' ; message selector printString
108 ; ' was not found for the following arguments:\n' ; message arguments printString.
109 message optionals isEmpty ifFalse:
110 [out ; '\nwith optionals:\n' ; message optionals printString].
114 conditions define: #MethodResentNotFound &parents: {MethodNotFound} &slots: {#method -> []}.
115 "A MethodNotFound when a resend is performed."
117 selector@(Symbol traits) notFoundOn: arguments after: method &optionals
119 (MethodResentNotFound new `>>
120 [message := Message sending: selector to: arguments &optionals: optionals.
121 method := method. ]) signal
124 mnf@(MethodResentNotFound traits) describeOn: out
126 out ; 'The method ' ; mnf message selector printString
127 ; ' was not found for the following arguments:\n' ; mnf message arguments printString
128 ; '\nafter method:\n' ; mnf method printString.
129 mnf message optionals isEmpty ifFalse:
130 [out ; '\nwith optionals:\n' ; mnf message optionals printString].
134 conditions define: #OverrideThis &parents: {ProtocolError}.
135 "An OverrideThis is an Error signaled when a method was not properly overridden."
137 _@(OverrideThis traits) describeOn: out
139 out ; 'The method was not defined by a child object as required.\n'
148 [error: 'This method should be implemented but is not.'].
150 _@lobby TODO: message
151 [error: 'This method should be implemented but is not.\nNote: ' ; message].
153 conditions define: #ShouldNotImplement &parents: {ProtocolError}.
154 "An ShouldNotImplement is an Error signaled when a method that shouldn't be defined is defined."
156 _@(ShouldNotImplement traits) describeOn: out
158 out ; 'The method should not be implemented on a child object.\n'
161 _@lobby shouldNotImplement
163 ShouldNotImplement signal
166 conditions define: #ConversionNotFound &parents: {Error} &slots: {#source. #target.}.
167 "A ConversionNotFound is an Error signaled when the use of as: is on arguments
168 for which no reasonable conversion exists."
170 x@(Root traits) conversionNotFoundTo: y
171 [(ConversionNotFound new `>> [source := x. target := y. ]) signal].
173 c@(ConversionNotFound traits) describeOn: out
175 out ; 'A suitable conversion method could not be found to convert between these two objects:\n'
176 ; c source printString ; '\n' ; c target printString ; '\n'.
179 numerics define: #OperationError &parents: {Error}.
180 "A numeric operation error. This offers the ability to continue with some
183 _@(OperationError traits) describeOn: out
185 out ; 'Numeric operation error.\n'
188 numerics define: #DivideByZero &parents: {numerics OperationError} &slots: {#dividend -> 0. "The number which division was taken on."}.
189 "A division by zero error."
191 e@(DivideByZero traits) describeOn: out
193 out ; 'Divide by zero of ' ; e dividend printString ; '.\n'
196 e@(DivideByZero traits) of: x
197 [e new `>> [dividend := x. ]].
199 Collection traits define: #Condition &parents: {Condition} &slots: {#collection.}.
201 cond@(Collection Condition traits) newFor: coll
202 [cond new `>> [collection := coll. ]].
204 cond@(Collection Condition traits) describeOn: out
206 out ; 'Collection ' ; cond collection printString
207 ; ' signaled: ' ; cond name ; '\n'.
210 Collection traits define: #ElementNotFound &parents: {Error. Collection Condition} &slots: {#element}.
212 enf@(Collection ElementNotFound traits) describeOn: out
214 out ; enf collection printString ; ' does not contain: '
215 ; enf element printString ; '\n'.
218 element elementNotFoundOn: c@(Collection traits)
220 (c ElementNotFound newFor: c) `>> [element := element. signal]
223 Collection traits define: #IsEmpty &parents: {Error. Collection Condition}.
225 ie@(Collection IsEmpty traits) describeOn: out
227 out ; ie collection printString ; ' is empty.\n'
230 c@(Collection traits) emptyCheck
232 c isEmpty ifTrue: [(c IsEmpty newFor: c) signal]
235 Collection traits define: #IsFull &parents: {Error. Collection Condition}.
237 if@(Collection IsFull traits) describeOn: out
239 out ; if collection printString ; ' is full.\n'
242 if@(Collection IsFull traits) defaultHandler
247 c@(Collection traits) fullCheck
249 c isFull ifTrue: [(c IsFull newFor: c) signal]
252 Mapping traits define: #KeyNotFound &parents: {Error. Collection Condition} &slots: {#key.}.
253 "A key which was not found in the specified collection."
255 knf@(Mapping KeyNotFound traits) describeOn: out
257 out ; knf key printString ; ' is not a key in '
258 ; knf collection printString ; '\n'.
261 key keyNotFoundOn: m@(Mapping traits)
262 [((m KeyNotFound newFor: m) `>> [key := key. ]) signal].