SignalSet.st
author Stefan Vogel <sv@exept.de>
Fri, 23 Mar 2001 14:43:18 +0100
changeset 5836 e8265b824b8f
parent 4547 082a2f7d9d8e
child 6396 74d5b0b588a6
permissions -rw-r--r--
Add signals to SignalSets with #,
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
5836
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    13
"{ Package: 'stx:libbasic' }"
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
IdentitySet subclass:#SignalSet
1275
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    16
	instanceVariableNames:''
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    17
	classVariableNames:'SetOfAnySignal'
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    18
	poolDictionaries:''
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    19
	category:'Kernel-Exceptions'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
44
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
    22
!SignalSet class methodsFor:'documentation'!
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
    23
88
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    26
 COPYRIGHT (c) 1993 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    27
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    28
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    36
!
81dacba7a63a *** empty log message ***
claus
parents: 71
diff changeset
    37
44
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
    38
documentation
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
    39
"
71
a42874820e27 *** empty log message ***
claus
parents: 44
diff changeset
    40
    SignalSet allows catching of multiple signals. A SignalSet consists of
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    41
    a number of signals and also implements the #handle:do: and #catch: methods
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    42
    just as signals do. 
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    43
    However, any signal from the SignalSet will, if signalled, lead into the handler.
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    44
71
a42874820e27 *** empty log message ***
claus
parents: 44
diff changeset
    45
    There is also a special signalSet, which can be used to catch any
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    46
    signal in the system - but this should no longer be used, since catching
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    47
    Object>>errorSignal has now the same effect.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    48
71
a42874820e27 *** empty log message ***
claus
parents: 44
diff changeset
    49
    For more detail, see comment in Signal and examples in doc/coding.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
    50
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    51
    Notice: SignalSets are not needed when a group of children of a common signal
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    52
    (such as arithmeticSignal) is to be handled; the parent signal of those will
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    53
    also handle all children.
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    54
    Use signalSets if totally unrelated signals should be handled by one common
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    55
    handler.
1275
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    56
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    57
1292
89497fff7f87 documentation
Claus Gittinger <cg@exept.de>
parents: 1275
diff changeset
    58
    [author:]
89497fff7f87 documentation
Claus Gittinger <cg@exept.de>
parents: 1275
diff changeset
    59
        Claus Gittinger
89497fff7f87 documentation
Claus Gittinger <cg@exept.de>
parents: 1275
diff changeset
    60
1275
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    61
    [see also:]
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    62
        Exception 
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    63
        Signal QuerySignal
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
    64
        Object
44
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
    65
"
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
    66
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
!SignalSet class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
anySignal
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    71
    "return a special signalSet for catching any signal.
2283
a1b388277558 commentary
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
    72
     Questionable:
a1b388277558 commentary
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
    73
        you should use 'Object>>errorSignal' for that purpose;
a1b388277558 commentary
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
    74
        however, the anySignal-set also catches nonChilds of the ErrorSignal
a1b388277558 commentary
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
    75
        (i.e. highly private, strange signals)."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
44
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
    77
    SetOfAnySignal isNil ifTrue:[
2283
a1b388277558 commentary
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
    78
        SetOfAnySignal := self basicNew
44
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
    79
    ].
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
    80
    ^ SetOfAnySignal
2283
a1b388277558 commentary
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
    81
a1b388277558 commentary
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
    82
    "Modified: 27.1.1997 / 20:31:08 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
5836
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    85
!SignalSet methodsFor:'adding'!
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    86
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    87
, anException
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    88
    "add anException to the set"
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    89
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    90
    self add:anException
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    91
! !
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
    92
622
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
!SignalSet methodsFor:'queries'!
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    94
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    95
accepts:aSignal
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    96
    "return true, if the receiver accepts the argument, aSignal.
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    97
     (i.e. if any of the receivers elements is aSignal or a parent of it).
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    98
     False otherwise. The special anySet accepts any (non-query) signal."
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    99
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   100
    (self == SetOfAnySignal) ifTrue:[^ aSignal isQuerySignal not].
4512
Claus Gittinger <cg@exept.de>
parents: 4491
diff changeset
   101
    self do:[:sig | (sig == aSignal or:[sig accepts:aSignal]) ifTrue:[^ true]].
622
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
    ^ false
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   103
!
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
4464
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   105
handlerForSignal:signal context:theContext originator:originator
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   106
    "answer the handler block for the signal from originator.
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   107
     The block is retrieved from aContext.
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   108
     Answer nil if the signal is not handled"
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   109
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   110
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   111
    (theContext selector ~~ #'handle:from:do:'
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   112
     or:[(theContext argAt:2) == originator]) ifTrue:[
4512
Claus Gittinger <cg@exept.de>
parents: 4491
diff changeset
   113
        (self == signal or:[self accepts:signal]) ifTrue:[
4464
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   114
            ^ theContext argAt:1
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   115
        ]
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   116
    ].
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   117
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   118
    ^ nil
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   119
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   120
    "Created: / 25.7.1999 / 23:46:48 / stefan"
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   121
!
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   122
4545
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   123
handlerProtectedBlock:doBlock inContext:context
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   124
    "set the handlerProtectedBlock in context"
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   125
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   126
    context selector == #handle:do: ifTrue:[
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   127
        context argAt:2 put:doBlock.
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   128
    ] ifFalse:[context selector == #handle:from:do: ifTrue:[
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   129
        context argAt:3 put:doBlock.
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   130
    ]].
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   131
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   132
    "
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   133
      SignalSet anySignal
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   134
          handle:[:ex| ex restartDo:[55]] do:[1 // 0]
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   135
    "
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   136
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   137
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   138
    "Created: / 25.7.1999 / 23:46:48 / stefan"
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   139
!
9671c4448040 Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4512
diff changeset
   140
4475
56d1dd81a41c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   141
handlingExceptionInContext:theContext
56d1dd81a41c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4473
diff changeset
   142
    "answer the handling signalSet from aContext."
4473
793078981f01 added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents: 4465
diff changeset
   143
793078981f01 added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents: 4465
diff changeset
   144
    ^ self
793078981f01 added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents: 4465
diff changeset
   145
793078981f01 added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents: 4465
diff changeset
   146
!
793078981f01 added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents: 4465
diff changeset
   147
622
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   148
includes:aSignal
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   149
    "return true, if the receiver contains the argument, aSignal.
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   150
     The special any-Set includes every (non-query) signal."
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   151
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   152
    (self == SetOfAnySignal) ifTrue:[
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   153
	^ (aSignal isSignal and:[aSignal isQuerySignal not])
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   154
    ].
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   155
    ^ super includes:aSignal
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   156
! !
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   157
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
!SignalSet methodsFor:'save evaluation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   159
622
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   160
catch:aBlock
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   161
     "evaluate the argument, aBlock.
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   162
      If any of the signals in the receiver is raised during evaluation, 
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   163
      abort the evaluation and return true; otherwise return false. 
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   164
      With the special anySignal, evaluation can be performed totally save 
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   165
      from signals 
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   166
      - but who (beside radical c++ fans) would do that ?"
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   167
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   168
      |raiseOccurred|
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   169
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   170
      raiseOccurred := false.
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   171
      self handle:[:ex | raiseOccurred := true. ex return] do:aBlock.
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   172
      ^ raiseOccurred
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   173
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   174
      "
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   175
       SignalSet anySignal catch:[
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   176
	  (#(1 2 3 4) at:5) / 0.0
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   177
       ]
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
      "
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   179
!
a17084b7ac06 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
handle:handleBlock do:aBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
    "evaluate the argument, aBlock.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   183
     If any of the signals in the receiver is raised during evaluation,
a27a279701f8 Initial revision
claus
parents:
diff changeset
   184
     evaluate the handleBlock passing it an Exception argument.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   185
     The handler may decide how to react to the signal by sending
a27a279701f8 Initial revision
claus
parents:
diff changeset
   186
     a corresponding message to the exception (see there).
a27a279701f8 Initial revision
claus
parents:
diff changeset
   187
     If the signal is not raised, return the value of evaluating
a27a279701f8 Initial revision
claus
parents:
diff changeset
   188
     aBlock."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   189
4547
082a2f7d9d8e Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4545
diff changeset
   190
    <context: #return>
4491
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   191
    <exception: #handle>
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   192
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   193
    "/ thisContext markForHandle. -- same as above pragma
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   194
    ^ aBlock value  "the real logic is in Exception>>doRaise"
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   195
4491
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   196
    "
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   197
     SignalSet anySignal handle:[:ex |
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   198
        ex errorString print. ' occured in: ' print. ex suspendedContext printNL.
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   199
        ex return
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   200
     ] do:[
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   201
        (#(1 2 3 4) at:5) / 0.0
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   202
     ]
4465
8dfbc6d6ccf3 Add example.
Stefan Vogel <sv@exept.de>
parents: 4464
diff changeset
   203
4491
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   204
     SignalSet anySignal handle:[:ex |
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   205
        ex errorString print. ' occured in: ' print. ex suspendedContext printNL.
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   206
        self bar.
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   207
        ex return
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   208
     ] do:[
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   209
        (#(1 2 3 4) at:5) / 0.0
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   210
     ]
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   211
    "
3308
a6848d4b875d Comments
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   212
4464
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   213
    "Modified: / 26.7.1999 / 00:03:13 / stefan"
44
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
   214
!
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
   215
362
claus
parents: 259
diff changeset
   216
handle:handleBlock from:anObject do:aBlock
claus
parents: 259
diff changeset
   217
    "evaluate the argument, aBlock.
claus
parents: 259
diff changeset
   218
     If any of the signals in the receiver is raised during evaluation,
claus
parents: 259
diff changeset
   219
     and the exception originated from anObject,
claus
parents: 259
diff changeset
   220
     evaluate the handleBlock passing it an Exception argument.
claus
parents: 259
diff changeset
   221
     The handler may decide how to react to the signal by sending
claus
parents: 259
diff changeset
   222
     a corresponding message to the exception (see there).
claus
parents: 259
diff changeset
   223
     If the signal is not raised, return the value of evaluating
claus
parents: 259
diff changeset
   224
     aBlock."
claus
parents: 259
diff changeset
   225
4547
082a2f7d9d8e Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents: 4545
diff changeset
   226
    <context: #return>
4491
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   227
    <exception: #handle>
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   228
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   229
    "/ thisContext markForHandle. -- same as above pragma
5041cae5651c use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents: 4486
diff changeset
   230
    ^ aBlock value  "the real logic is in Exception>>doRaise"
3308
a6848d4b875d Comments
Stefan Vogel <sv@exept.de>
parents: 2284
diff changeset
   231
4464
cec93c942c14 Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents: 3311
diff changeset
   232
    "Modified: / 26.7.1999 / 00:03:06 / stefan"
362
claus
parents: 259
diff changeset
   233
!
claus
parents: 259
diff changeset
   234
2284
8b29d42bb03d oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents: 2283
diff changeset
   235
ignoreIn:aBlock
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   236
     "evaluate the argument, aBlock.
2284
8b29d42bb03d oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents: 2283
diff changeset
   237
      Ignore the any signals from the receiver during evaluation - i.e. simply
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   238
      continue. This makes only sense for some signals, such as UserInterrupt
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   239
      or AbortSignals, because continuing after an exception without any cleanup
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   240
      will often lead to followup-errors."
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   241
4486
f84def7aaf3f replaced #proceed with #proceedWith:nil
Claus Gittinger <cg@exept.de>
parents: 4475
diff changeset
   242
      ^ self handle:[:ex | ex proceedWith:nil] do:aBlock.
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   243
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   244
      "
3311
2f7f489ebff8 example comment
Claus Gittinger <cg@exept.de>
parents: 3308
diff changeset
   245
       SignalSet anySignal ignoreIn:[
2284
8b29d42bb03d oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents: 2283
diff changeset
   246
          123 size open   
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   247
       ]
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   248
      "
2284
8b29d42bb03d oops - renamed #ignore: to #ignoreIn:
Claus Gittinger <cg@exept.de>
parents: 2283
diff changeset
   249
3311
2f7f489ebff8 example comment
Claus Gittinger <cg@exept.de>
parents: 3308
diff changeset
   250
    "Created: / 27.1.1997 / 20:32:50 / cg"
2f7f489ebff8 example comment
Claus Gittinger <cg@exept.de>
parents: 3308
diff changeset
   251
    "Modified: / 4.3.1998 / 16:36:30 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   252
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   253
696
d11342e8b7ad checkin from browser
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   254
!SignalSet class methodsFor:'documentation'!
d11342e8b7ad checkin from browser
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   255
d11342e8b7ad checkin from browser
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   256
version
5836
e8265b824b8f Add signals to SignalSets with #,
Stefan Vogel <sv@exept.de>
parents: 4547
diff changeset
   257
    ^ '$Header: /cvs/stx/stx/libbasic/SignalSet.st,v 1.34 2001-03-23 13:43:18 stefan Exp $'
696
d11342e8b7ad checkin from browser
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   258
! !