author | Stefan Vogel <sv@exept.de> |
Fri, 03 Apr 2020 18:50:48 +0200 | |
changeset 5471 | 0bee7a5e40e8 |
parent 785 | d7e55477dba2 |
permissions | -rw-r--r-- |
43 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
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 |
||
13 |
OrderedCollection subclass:#HandlerCollection |
|
785
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
14 |
instanceVariableNames:'' |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
15 |
classVariableNames:'' |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
16 |
poolDictionaries:'' |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
17 |
category:'Kernel-Exceptions' |
43 | 18 |
! |
19 |
||
20 |
!HandlerCollection class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
A HandlerCollection allows a group of unrelated signals to be handled |
|
39 |
by individual handlers - their evaluation is equivalent to a corresponding |
|
40 |
number of nested signal handlers, but somwehat easier to program. |
|
41 |
In the real world, handlerCollections are seldom needed and actually currently |
|
42 |
not used by the system. |
|
43 |
" |
|
44 |
! ! |
|
45 |
||
785
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
46 |
!HandlerCollection methodsFor:'adding'! |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
47 |
|
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
48 |
on:aSignal handle:aHandler |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
49 |
"add a signal<->handler pair to the receiver collection" |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
50 |
|
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
51 |
self addFirst:(aSignal -> aHandler) |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
52 |
! ! |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
53 |
|
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
54 |
!HandlerCollection methodsFor:'private'! |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
55 |
|
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
56 |
from:start to:stop handleDo:aBlock |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
57 |
"this method recursively sets up a bunch of nested |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
58 |
handlers, and finally evaluates the argument, aBlock" |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
59 |
|
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
60 |
|signalHandlerPair| |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
61 |
|
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
62 |
stop < start ifTrue:[ |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
63 |
^ aBlock value |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
64 |
]. |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
65 |
signalHandlerPair := self at:start. |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
66 |
^ (signalHandlerPair key) |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
67 |
handle:(signalHandlerPair value) |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
68 |
do:[self from:start+1 to:stop handleDo:aBlock] |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
69 |
! ! |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
70 |
|
43 | 71 |
!HandlerCollection methodsFor:'save evaluation'! |
72 |
||
73 |
handleDo:aBlock |
|
74 |
"evaluate the argument, aBlock. |
|
75 |
If any of the signals in the receiver is raised during evaluation, |
|
76 |
evaluate the corresponding handleBlock from the receiver, |
|
77 |
passing it an Exception argument. |
|
78 |
The handler may decide how to react to the signal by sending |
|
79 |
a corresponding message to the exception (see there). |
|
80 |
If none of the signals is raised during evaluation, return the |
|
81 |
value returned by aBlock." |
|
82 |
||
83 |
^ self from:1 to:self size handleDo:aBlock |
|
84 |
||
85 |
" |
|
86 |
|h num| |
|
87 |
||
88 |
h := HandlerCollection new. |
|
89 |
h on:(Number divisionByZeroSignal) |
|
90 |
handle:[:ex | 'division by zero' printNL. ex proceed]. |
|
91 |
||
92 |
h on:(Object haltSignal) |
|
93 |
handle:[:ex | 'halt encountered ' printNL. ex proceed]. |
|
94 |
||
95 |
h on:(Float domainErrorSignal) |
|
96 |
handle:[:ex | 'domain error ' printNL. ex proceed]. |
|
97 |
||
98 |
h handleDo:[ |
|
99 |
num := 0. |
|
100 |
||
101 |
'now dividing' printNL. |
|
102 |
1 // num. |
|
103 |
||
104 |
'now doing bad arcSin' printNL. |
|
105 |
num := 50. |
|
106 |
num arcSin. |
|
107 |
||
108 |
'now halting' printNL. |
|
109 |
self halt. |
|
110 |
] |
|
111 |
" |
|
112 |
! ! |
|
113 |
||
785
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
114 |
!HandlerCollection class methodsFor:'documentation'! |
43 | 115 |
|
785
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
116 |
version |
d7e55477dba2
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
117 |
^ '$Header: /cvs/stx/stx/libbasic2/HandlerCollection.st,v 1.5 1999-07-28 21:00:09 cg Exp $' |
43 | 118 |
! ! |