15694
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2013 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libbasic' }"
|
|
13 |
|
|
14 |
Notification subclass:#ProceedingNotification
|
|
15 |
instanceVariableNames:''
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Kernel-Exceptions'
|
|
19 |
!
|
|
20 |
|
|
21 |
!ProceedingNotification class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2013 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
A ProceedingNotification behaves much like a regular notification,
|
|
40 |
in that if no handler is present, execution proceeds after the raise.
|
|
41 |
However, iff a handler simply falls through, the exception is proceeded.
|
|
42 |
The handler is still free to choose for an explicit action (return/reject).
|
|
43 |
|
|
44 |
[author:]
|
|
45 |
Claus Gittinger
|
|
46 |
|
|
47 |
[see also:]
|
|
48 |
Exception Query Notification
|
|
49 |
"
|
|
50 |
!
|
|
51 |
|
|
52 |
examples
|
|
53 |
"
|
|
54 |
an up-notification from a deeply nested operation to a higher level.
|
|
55 |
Notice, that in contrast to a regular Notification, all outer handlers are called:
|
|
56 |
[exBegin]
|
|
57 |
|zero|
|
|
58 |
|
|
59 |
zero := 0.
|
|
60 |
CascadingNotification handle:[:n |
|
|
61 |
Transcript showCR:'h1: ' , n description.
|
|
62 |
n proceedWith:1.
|
|
63 |
] do:[
|
|
64 |
CascadingNotification handle:[:n |
|
|
65 |
Transcript showCR:'h2: ' , n description.
|
|
66 |
] do:[
|
|
67 |
CascadingNotification handle:[:n |
|
|
68 |
Transcript showCR:'h3: ' , n description.
|
|
69 |
] do:[
|
|
70 |
'nesting'.
|
|
71 |
[
|
|
72 |
[
|
|
73 |
Error handle:[:ex |
|
|
74 |
Transcript showCR:'some error: ' , ex errorString.
|
|
75 |
ex proceed
|
|
76 |
] do:[
|
|
77 |
[
|
|
78 |
|answer|
|
|
79 |
|
|
80 |
1 // zero. 'an error which is caught in the handler'.
|
|
81 |
answer := CascadingNotification notify:'hello world'.
|
|
82 |
Transcript show:'after notification 1: '; showCR:answer.
|
|
83 |
] value
|
|
84 |
]
|
|
85 |
] value
|
|
86 |
] value.
|
|
87 |
Transcript showCR:'after notification 2'.
|
|
88 |
].
|
|
89 |
Transcript showCR:'after notification 3'.
|
|
90 |
].
|
|
91 |
Transcript showCR:'after notification 4'.
|
|
92 |
].
|
|
93 |
Transcript showCR:'after notification 5'.
|
|
94 |
[exEnd]
|
|
95 |
|
|
96 |
however, if any handler proceeds or returns, this is not the case:
|
|
97 |
[exBegin]
|
|
98 |
|zero|
|
|
99 |
|
|
100 |
zero := 0.
|
|
101 |
CascadingNotification handle:[:n |
|
|
102 |
Transcript showCR:'h1: ' , n description.
|
|
103 |
] do:[
|
|
104 |
CascadingNotification handle:[:n |
|
|
105 |
Transcript showCR:'h2: ' , n description.
|
|
106 |
n proceedWith:2.
|
|
107 |
] do:[
|
|
108 |
CascadingNotification handle:[:n |
|
|
109 |
Transcript showCR:'h3: ' , n description.
|
|
110 |
] do:[
|
|
111 |
'nesting'.
|
|
112 |
[
|
|
113 |
[
|
|
114 |
Error handle:[:ex |
|
|
115 |
Transcript showCR:'some error: ' , ex errorString.
|
|
116 |
ex proceed
|
|
117 |
] do:[
|
|
118 |
[
|
|
119 |
|answer|
|
|
120 |
|
|
121 |
1 // zero. 'an error which is caught in the handler'.
|
|
122 |
answer := CascadingNotification notify:'hello world'.
|
|
123 |
Transcript show:'after notification 1: '; showCR:answer.
|
|
124 |
] value
|
|
125 |
]
|
|
126 |
] value
|
|
127 |
] value.
|
|
128 |
Transcript showCR:'after notification 2'.
|
|
129 |
].
|
|
130 |
Transcript showCR:'after notification 3'.
|
|
131 |
].
|
|
132 |
Transcript showCR:'after notification 4'.
|
|
133 |
].
|
|
134 |
Transcript showCR:'after notification 5'.
|
|
135 |
[exEnd]
|
|
136 |
however, if any handler proceeds or returns, this is not the case:
|
|
137 |
[exBegin]
|
|
138 |
|zero|
|
|
139 |
|
|
140 |
zero := 0.
|
|
141 |
CascadingNotification handle:[:n |
|
|
142 |
Transcript showCR:'h1: ' , n description.
|
|
143 |
] do:[
|
|
144 |
CascadingNotification handle:[:n |
|
|
145 |
Transcript showCR:'h2: ' , n description.
|
|
146 |
n return.
|
|
147 |
] do:[
|
|
148 |
CascadingNotification handle:[:n |
|
|
149 |
Transcript showCR:'h3: ' , n description.
|
|
150 |
] do:[
|
|
151 |
'nesting'.
|
|
152 |
[
|
|
153 |
[
|
|
154 |
Error handle:[:ex |
|
|
155 |
Transcript showCR:'some error: ' , ex errorString.
|
|
156 |
ex proceed
|
|
157 |
] do:[
|
|
158 |
[
|
|
159 |
|answer|
|
|
160 |
|
|
161 |
1 // zero. 'an error which is caught in the handler'.
|
|
162 |
answer := CascadingNotification notify:'hello world'.
|
|
163 |
Transcript show:'after notification 1: '; showCR:answer.
|
|
164 |
] value
|
|
165 |
]
|
|
166 |
] value
|
|
167 |
] value.
|
|
168 |
Transcript showCR:'after notification 2'.
|
|
169 |
].
|
|
170 |
Transcript showCR:'after notification 3'.
|
|
171 |
].
|
|
172 |
Transcript showCR:'after notification 4'.
|
|
173 |
].
|
|
174 |
Transcript showCR:'after notification 5'.
|
|
175 |
[exEnd]
|
|
176 |
"
|
|
177 |
! !
|
|
178 |
|
|
179 |
!ProceedingNotification class methodsFor:'initialization'!
|
|
180 |
|
|
181 |
initialize
|
|
182 |
|
|
183 |
NotifierString := 'Notification:'
|
|
184 |
! !
|
|
185 |
|
|
186 |
!ProceedingNotification methodsFor:'default actions'!
|
|
187 |
|
|
188 |
doCallHandler:aHandlerBlock
|
|
189 |
"call the handler proper - if the handler falls through, proceed with the handler's value.
|
|
190 |
- an extra method is needed to have a raise-marked context around.
|
|
191 |
(see implementation of #reject and #proceed)."
|
|
192 |
|
|
193 |
<context: #return>
|
|
194 |
<exception: #raise>
|
|
195 |
|
|
196 |
|val|
|
|
197 |
|
|
198 |
aHandlerBlock argumentCount == 0 ifTrue:[
|
|
199 |
"0-arg handler or any object - not interested in the exception argument"
|
|
200 |
val := aHandlerBlock value
|
|
201 |
] ifFalse:[
|
|
202 |
"1-arg handler - pass myself as exception argument"
|
|
203 |
val := aHandlerBlock value:self.
|
|
204 |
].
|
|
205 |
|
|
206 |
"handler fall through - this is different here!!"
|
|
207 |
|
|
208 |
self proceedWith:val
|
|
209 |
! !
|
|
210 |
|
|
211 |
!ProceedingNotification class methodsFor:'documentation'!
|
|
212 |
|
|
213 |
version
|
|
214 |
^ '$Header: /cvs/stx/stx/libbasic/ProceedingNotification.st,v 1.1 2013-08-24 12:25:37 cg Exp $'
|
|
215 |
!
|
|
216 |
|
|
217 |
version_CVS
|
|
218 |
^ '$Header: /cvs/stx/stx/libbasic/ProceedingNotification.st,v 1.1 2013-08-24 12:25:37 cg Exp $'
|
|
219 |
! !
|
|
220 |
|
|
221 |
|
|
222 |
ProceedingNotification initialize!
|