forked from amber-smalltalk/amber
/
Kernel-Exceptions.st
124 lines (90 loc) · 1.99 KB
/
Kernel-Exceptions.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Smalltalk current createPackage: 'Kernel-Exceptions' properties: #{}!
Object subclass: #Error
instanceVariableNames: 'messageText'
category: 'Kernel-Exceptions'!
!Error methodsFor: 'accessing'!
messageText
^messageText
!
messageText: aString
messageText := aString
!
context
<return self.context>
!
jsStack
<return self.stack>
! !
!Error methodsFor: 'signaling'!
signal
<self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
! !
!Error methodsFor: 'testing'!
isSmalltalkError
<return self.smalltalkError === true>
! !
!Error class methodsFor: 'instance creation'!
signal: aString
^self new
messageText: aString;
signal
! !
Error subclass: #MessageNotUnderstood
instanceVariableNames: 'message receiver'
category: 'Kernel-Exceptions'!
!MessageNotUnderstood methodsFor: 'accessing'!
message
^message
!
message: aMessage
message := aMessage
!
receiver
^receiver
!
receiver: anObject
receiver := anObject
!
messageText
^self receiver asString, ' does not understand #', self message selector
! !
Object subclass: #ErrorHandler
instanceVariableNames: ''
category: 'Kernel-Exceptions'!
!ErrorHandler methodsFor: 'error handling'!
handleError: anError
anError context ifNotNil: [self logErrorContext: anError context].
self logError: anError
! !
!ErrorHandler methodsFor: 'private'!
logContext: aContext
aContext home ifNotNil: [
self logContext: aContext home].
self log: aContext receiver asString, '>>', aContext selector
!
logErrorContext: aContext
aContext ifNotNil: [
aContext home ifNotNil: [
self logContext: aContext home]]
!
logError: anError
self log: anError messageText
!
log: aString
console log: aString
! !
ErrorHandler class instanceVariableNames: 'current'!
!ErrorHandler class methodsFor: 'accessing'!
current
^current ifNil: [current := self new]
!
setCurrent: anHandler
current := anHandler
! !
!ErrorHandler class methodsFor: 'initialization'!
initialize
self register
!
register
ErrorHandler setCurrent: self new
! !