author | Claus Gittinger <cg@exept.de> |
Thu, 03 Aug 2017 16:41:13 +0200 | |
changeset 22159 | c8f19ee3f888 |
parent 15693 | eb98bc67197f |
permissions | -rw-r--r-- |
15670 | 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:#CascadingNotification |
|
15 |
instanceVariableNames:'' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Kernel-Exceptions' |
|
19 |
! |
|
20 |
||
21 |
!CascadingNotification 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 CascadingNotification behaves much like a regular notification, |
|
40 |
in that if no handler is present, execution proceeds after the raise. |
|
41 |
However, iff a handler is present, all other outer handlers are still called, |
|
15693
eb98bc67197f
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15682
diff
changeset
|
42 |
if the handles simply fall through |
eb98bc67197f
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15682
diff
changeset
|
43 |
I.e. the default behavior of a handler is not to proceed or return, but to reject, |
eb98bc67197f
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15682
diff
changeset
|
44 |
iff there is another outer handler. |
eb98bc67197f
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15682
diff
changeset
|
45 |
For the very outermost handler, the default is to proceed. |
15670 | 46 |
|
47 |
This is used to allow for notifier-hooks to be stacked upon each other. |
|
48 |
For now, the one and only use is the aboutToOpenBox notifier, which can be used |
|
49 |
as a hook to add additional widget components to a standard dialog box. |
|
50 |
||
51 |
[author:] |
|
52 |
Claus Gittinger |
|
53 |
||
54 |
[see also:] |
|
55 |
Exception Query Notification |
|
56 |
" |
|
57 |
! |
|
58 |
||
59 |
examples |
|
60 |
" |
|
61 |
an up-notification from a deeply nested operation to a higher level. |
|
62 |
Notice, that in contrast to a regular Notification, all outer handlers are called: |
|
63 |
[exBegin] |
|
64 |
|zero| |
|
65 |
||
66 |
zero := 0. |
|
67 |
CascadingNotification handle:[:n | |
|
68 |
Transcript showCR:'h1: ' , n description. |
|
15682
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
69 |
n proceedWith:1. |
15670 | 70 |
] do:[ |
71 |
CascadingNotification handle:[:n | |
|
72 |
Transcript showCR:'h2: ' , n description. |
|
73 |
] do:[ |
|
74 |
CascadingNotification handle:[:n | |
|
75 |
Transcript showCR:'h3: ' , n description. |
|
76 |
] do:[ |
|
77 |
'nesting'. |
|
78 |
[ |
|
79 |
[ |
|
80 |
Error handle:[:ex | |
|
81 |
Transcript showCR:'some error: ' , ex errorString. |
|
82 |
ex proceed |
|
83 |
] do:[ |
|
84 |
[ |
|
15682
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
85 |
|answer| |
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
86 |
|
15670 | 87 |
1 // zero. 'an error which is caught in the handler'. |
15682
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
88 |
answer := CascadingNotification notify:'hello world'. |
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
89 |
Transcript show:'after notification 1: '; showCR:answer. |
15670 | 90 |
] value |
91 |
] |
|
92 |
] value |
|
93 |
] value. |
|
94 |
Transcript showCR:'after notification 2'. |
|
95 |
]. |
|
96 |
Transcript showCR:'after notification 3'. |
|
97 |
]. |
|
98 |
Transcript showCR:'after notification 4'. |
|
99 |
]. |
|
100 |
Transcript showCR:'after notification 5'. |
|
101 |
[exEnd] |
|
102 |
||
103 |
however, if any handler proceeds or returns, this is not the case: |
|
104 |
[exBegin] |
|
105 |
|zero| |
|
106 |
||
107 |
zero := 0. |
|
108 |
CascadingNotification handle:[:n | |
|
109 |
Transcript showCR:'h1: ' , n description. |
|
110 |
] do:[ |
|
111 |
CascadingNotification handle:[:n | |
|
112 |
Transcript showCR:'h2: ' , n description. |
|
15682
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
113 |
n proceedWith:2. |
15670 | 114 |
] do:[ |
115 |
CascadingNotification handle:[:n | |
|
116 |
Transcript showCR:'h3: ' , n description. |
|
117 |
] do:[ |
|
118 |
'nesting'. |
|
119 |
[ |
|
120 |
[ |
|
121 |
Error handle:[:ex | |
|
122 |
Transcript showCR:'some error: ' , ex errorString. |
|
123 |
ex proceed |
|
124 |
] do:[ |
|
125 |
[ |
|
15682
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
126 |
|answer| |
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
127 |
|
15670 | 128 |
1 // zero. 'an error which is caught in the handler'. |
15682
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
129 |
answer := CascadingNotification notify:'hello world'. |
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
130 |
Transcript show:'after notification 1: '; showCR:answer. |
15670 | 131 |
] value |
132 |
] |
|
133 |
] value |
|
134 |
] value. |
|
135 |
Transcript showCR:'after notification 2'. |
|
136 |
]. |
|
137 |
Transcript showCR:'after notification 3'. |
|
138 |
]. |
|
139 |
Transcript showCR:'after notification 4'. |
|
140 |
]. |
|
141 |
Transcript showCR:'after notification 5'. |
|
142 |
[exEnd] |
|
143 |
however, if any handler proceeds or returns, this is not the case: |
|
144 |
[exBegin] |
|
145 |
|zero| |
|
146 |
||
147 |
zero := 0. |
|
148 |
CascadingNotification handle:[:n | |
|
149 |
Transcript showCR:'h1: ' , n description. |
|
150 |
] do:[ |
|
151 |
CascadingNotification handle:[:n | |
|
152 |
Transcript showCR:'h2: ' , n description. |
|
153 |
n return. |
|
154 |
] do:[ |
|
155 |
CascadingNotification handle:[:n | |
|
156 |
Transcript showCR:'h3: ' , n description. |
|
157 |
] do:[ |
|
158 |
'nesting'. |
|
159 |
[ |
|
160 |
[ |
|
161 |
Error handle:[:ex | |
|
162 |
Transcript showCR:'some error: ' , ex errorString. |
|
163 |
ex proceed |
|
164 |
] do:[ |
|
165 |
[ |
|
15682
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
166 |
|answer| |
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
167 |
|
15670 | 168 |
1 // zero. 'an error which is caught in the handler'. |
15682
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
169 |
answer := CascadingNotification notify:'hello world'. |
b52b3fbe9456
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15670
diff
changeset
|
170 |
Transcript show:'after notification 1: '; showCR:answer. |
15670 | 171 |
] value |
172 |
] |
|
173 |
] value |
|
174 |
] value. |
|
175 |
Transcript showCR:'after notification 2'. |
|
176 |
]. |
|
177 |
Transcript showCR:'after notification 3'. |
|
178 |
]. |
|
179 |
Transcript showCR:'after notification 4'. |
|
180 |
]. |
|
181 |
Transcript showCR:'after notification 5'. |
|
182 |
[exEnd] |
|
183 |
" |
|
184 |
! ! |
|
185 |
||
186 |
!CascadingNotification class methodsFor:'initialization'! |
|
187 |
||
188 |
initialize |
|
189 |
||
190 |
NotifierString := 'Notification:' |
|
191 |
! ! |
|
192 |
||
193 |
!CascadingNotification methodsFor:'default actions'! |
|
194 |
||
195 |
doCallHandler:aHandlerBlock |
|
15693
eb98bc67197f
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15682
diff
changeset
|
196 |
"call the handler proper - if the handler falls through, reject and try more handlers. |
15670 | 197 |
- an extra method is needed to have a raise-marked context around. |
198 |
(see implementation of #reject and #proceed)." |
|
199 |
||
200 |
<context: #return> |
|
201 |
<exception: #raise> |
|
202 |
||
203 |
|val| |
|
204 |
||
205 |
aHandlerBlock argumentCount == 0 ifTrue:[ |
|
206 |
"0-arg handler or any object - not interested in the exception argument" |
|
207 |
val := aHandlerBlock value |
|
208 |
] ifFalse:[ |
|
209 |
"1-arg handler - pass myself as exception argument" |
|
210 |
val := aHandlerBlock value:self. |
|
211 |
]. |
|
212 |
||
213 |
"handler fall through - this is different here!!" |
|
214 |
||
215 |
self reject |
|
216 |
! ! |
|
217 |
||
218 |
!CascadingNotification class methodsFor:'documentation'! |
|
219 |
||
220 |
version |
|
15693
eb98bc67197f
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15682
diff
changeset
|
221 |
^ '$Header: /cvs/stx/stx/libbasic/CascadingNotification.st,v 1.3 2013-08-24 12:24:42 cg Exp $' |
15670 | 222 |
! |
223 |
||
224 |
version_CVS |
|
15693
eb98bc67197f
class: CascadingNotification
Claus Gittinger <cg@exept.de>
parents:
15682
diff
changeset
|
225 |
^ '$Header: /cvs/stx/stx/libbasic/CascadingNotification.st,v 1.3 2013-08-24 12:24:42 cg Exp $' |
15670 | 226 |
! ! |
227 |
||
228 |
||
229 |
CascadingNotification initialize! |