Exception.st
author claus
Mon, 01 May 1995 23:30:32 +0200
changeset 328 7b542c0bf1dd
parent 326 d2902942491d
child 345 cf2301210c47
permissions -rw-r--r--
.
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
171
129f0e2e23df handling now in Exception
claus
parents: 142
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
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
Object subclass:#Exception
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    14
	 instanceVariableNames:'signal parameter errorString
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    15
				suspendedContext handlerContext
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    16
				rejected
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    17
				resumeBlock rejectBlock'
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    18
	 classVariableNames:'EmergencyHandler RecursiveExceptionSignal'
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    19
	 poolDictionaries:''
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    20
	 category:'Kernel-Exceptions'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
Exception comment:'
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
COPYRIGHT (c) 1993 by Claus Gittinger
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    25
	      All Rights Reserved
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    26
328
claus
parents: 326
diff changeset
    27
$Header: /cvs/stx/stx/libbasic/Exception.st,v 1.20 1995-05-01 21:29:20 claus Exp $
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
    28
'!
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
    29
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
    30
!Exception class methodsFor:'documentation'!
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
    31
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 COPYRIGHT (c) 1993 by Claus Gittinger
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    35
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    44
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    45
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
version
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    47
"
328
claus
parents: 326
diff changeset
    48
$Header: /cvs/stx/stx/libbasic/Exception.st,v 1.20 1995-05-01 21:29:20 claus Exp $
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    49
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    50
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    51
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
    52
documentation
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
    53
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    54
    Instances of Exception are passed to a Signal handling block as argument.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    55
    The handler block may perform various actions by sending corresponding messages
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    56
    to the exception object. The following actions are possible:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    57
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    58
	reject          - dont handle this signal;
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    59
			  another handler will be searched for, 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    60
			  upper in the calling hierarchy
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    61
			  (this is also the handlers default, if it falls through)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    62
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    63
	proceed         - return from the Signal>>raise, with nil as value
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    64
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    65
	proceedWith:val - same, but return val from Signal>>raise
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    67
	return          - return from the Signal>>handle:do:, with nil as value
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    68
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    69
	return:val      - same, but return val from Signal>>handle:do:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    71
	restart         - restart the Signal>>handle:do:, after repairing
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    73
    Via the Exception object, the handler can also query the state of execution:
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    74
    where the Signal was raised, where the handler is, the signal which caused
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    75
    the error and the errorString passed when the signal was raised. Also, an optional
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    76
    parameter can be passed - the use is signal specific.:
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
    77
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    78
    instance variables:
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    79
	signal           <Signal>     the signal which caused the exception
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    80
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    81
	parameter        <Object>     a parameter (if any) which was passed when raising
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    82
				      the signal (only if raised with #raiseWith:aParameter)
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    83
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    84
	errorString      <String>     an errorString 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    85
				      (usually the signals own errorString, but sometimes
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    86
				       changed explicitely in #raiseWith:errorString:)
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
    87
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    88
	suspendedContext <Context>    the context in which the raise occured
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    89
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    90
	handlerContext   <Context>    the context of the handler (if any)
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    91
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    92
	resumeBlock      <Block>      private to the exception; needed to perform resume action
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
    93
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    94
	rejectBlock      <Block>      private to the exception; needed to perform reject action
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
    95
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    96
    In case of an unhandled signal raise, Exceptions EmergenyHandler will be evaluated. 
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    97
    The default emergeny handler will enter the debugger.
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    98
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    99
    For applications, which do not want Debuggers to come up, other handlers are
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   100
    possible.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   101
    For example: to get the typical C++ behavior, use:
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   102
	Exception emergencyHandler:[:ex | Smalltalk exitWithCoreDump]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   103
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   104
    Class variables:
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   105
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   106
	EmergencyHandler <Block>    this block is evaluated, if no handler was defined
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   107
				    for a signal (i.e. this one is responsible for the
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   108
				    unhandled exception debugger).
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   109
				    Having this being a block allows to globally catch
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   110
				    these errors - even when no enclosing handler-scope
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   111
				    around the erronous code exists.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   112
				    (as the catch/through does).
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   113
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   114
	RecursiveExceptionSignal
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   115
			 <Signal>   raised when within a handler for some signal,
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   116
				    th same signal is raised again.
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   117
"
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   118
! !
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   119
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   120
!Exception class methodsFor:'initialization'!
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   121
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   122
initialize 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   123
    "setup the signal used to handle unhandled signals"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   124
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   125
    RecursiveExceptionSignal isNil ifTrue:[
302
1f76060d58a4 *** empty log message ***
claus
parents: 255
diff changeset
   126
	RecursiveExceptionSignal := ErrorSignal newSignalMayProceed:false.
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   127
	RecursiveExceptionSignal nameClass:self message:#recursiveExceptionSignal.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   128
	RecursiveExceptionSignal notifierString:'recursive signal raise in handler'
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   129
    ]
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   130
! !
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   131
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   132
!Exception class methodsFor:'signal access'!
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   133
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   134
recursiveExceptionSignal
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   135
    "return the signal used to handle recursive signals in the handlers"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   136
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   137
    ^ RecursiveExceptionSignal
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   138
! !
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   139
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   140
!Exception class methodsFor:'defaults'!
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   141
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   142
emergencyHandler
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   143
    "return the handler used for unhandled exceptions"
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   144
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   145
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   146
     set it up, when called the first time
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   147
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   148
    EmergencyHandler isNil ifTrue:[
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   149
	EmergencyHandler := [:ex |
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   150
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   151
	     sending it to the signal allows per-signal specific
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   152
	     debuggers to be implemented in the future
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   153
	     (for example, segv in primitive code could show things 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   154
	      on the C-level ..)
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   155
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   156
	    (ex signal) enterDebuggerWith:ex message:(ex errorString).
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   157
	]
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   158
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   159
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   160
    ^ EmergencyHandler
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   161
!
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   162
130
e09411db2573 emergencyhandler is now a one-arg-block
claus
parents: 92
diff changeset
   163
emergencyHandler:aOneArgBlock
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   164
    "set the handler used for unhandled exceptions"
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   165
130
e09411db2573 emergencyhandler is now a one-arg-block
claus
parents: 92
diff changeset
   166
    EmergencyHandler := aOneArgBlock
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   167
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
a27a279701f8 Initial revision
claus
parents:
diff changeset
   169
!Exception methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   170
a27a279701f8 Initial revision
claus
parents:
diff changeset
   171
signal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   172
    "return the signal, that caused the exception"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   173
a27a279701f8 Initial revision
claus
parents:
diff changeset
   174
    ^ signal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   176
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   177
parameter
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   178
    "return the parameter passsed with the signal raise
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   179
     (or nil, if there was none)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
    ^ parameter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   183
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   184
errorString 
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   185
    "return the errorString passsed with the signal raise
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   186
     (or nil, if there was none)"
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   187
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   188
    ^ errorString
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   189
!
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   190
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   191
handlerContext
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   192
    "return the context of the handler"
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   193
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   194
    ^ handlerContext
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   195
!
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   196
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   197
suspendedContext
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   198
    "return the context in which the raise occured"
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   199
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   200
    ^ suspendedContext
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   201
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   202
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   203
rejected
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   204
    "return true, if the exception handler rejected 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   205
     (in contrast to a handler falling through).
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   206
     Uncertain, if thais is really interresting to anybody.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   207
     Notice: this is only valid immediately after handler execution."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   208
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   209
    ^ rejected
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   211
a27a279701f8 Initial revision
claus
parents:
diff changeset
   212
!Exception methodsFor:'setup'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   213
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   214
signal:aSignal parameter:aParameter errorString:aString suspendedContext:sContext
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   215
    "set the fields usable for inspection by the handler
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   216
     - only to be sent from the signal when raising"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   217
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   218
    signal := aSignal.
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   219
    parameter := aParameter.
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   220
    errorString := aString.
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   221
    suspendedContext := sContext.
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   222
! !
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   223
217
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   224
!Exception methodsFor:'raising'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   225
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   226
raise
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   227
    "actually raise an exception"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   228
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   229
    resumeBlock := [:value | ^ value].
217
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   230
    ^ self evaluateHandler
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   231
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   233
evaluateHandler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   234
    "search through the context-calling chain for a 'handle:do:'-context 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   235
     to the raising signal a parent of it or a SignalSet which includes 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   236
     the raising signal.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   237
     If found, take the contexts 2nd argument (the handler) and evaluate
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   238
     it with the receiver exception as argument.
217
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   239
     If no handler is found, try per signal handler, or
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   240
     per process handler (if its the noHandlerSignal).
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   241
     Finally fall back to Exceptions emergencyHandler, which is always
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   242
     available and enters the debugger."
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   243
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   244
    |con block noHandlerSignal|
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   245
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   246
    con := thisContext sender.  "the raise-context"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   247
    con := con sender.          "the signal raise context"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   248
    con isRecursive ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   249
	"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   250
	 mhmh - an error while in a handler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   251
	"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   252
	((signal == RecursiveExceptionSignal)
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   253
	or:[RecursiveExceptionSignal isNil]) ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   254
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   255
	     ... either while handling RecursiveExceptionSignal
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   256
	     or at startup when RecursiveExceptionSignal is not yet
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   257
	     created -
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   258
	     - go immediately into the debugger.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   259
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   260
	    ^ self enterDebuggerWith:self
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   261
			     message:'recursive signal raise'
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   262
	].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   263
	^ RecursiveExceptionSignal 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   264
	    raiseRequestWith:self 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   265
		 errorString:('recursive signal raise: ' , errorString)
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   266
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   267
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   268
    [con notNil] whileTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   269
	(con selector == #'handle:do:') ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   270
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   271
	     if this is the Signal>>handle:do: context
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   272
	     or a SignalSet>>handle:do: context with self in it,
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   273
	     call the handler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   274
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   275
	    (con receiver accepts:signal) ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   276
		"call the handler"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   277
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   278
		handlerContext := con.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   279
		self doCallHandler:(con args at:1).
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   280
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   281
		"if the handler rejects or falls through we arrive here"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   282
		"continue search for another handler"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   283
	    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   284
	].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   285
	con := con sender
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   286
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   287
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   288
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   289
     we arrive here, if either no handler was found, or none of the
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   290
     handlers did a return (i.e. every handler rejected or fell through).
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   291
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   292
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   293
     try per signal handler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   294
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   295
    (block := signal handlerBlock) notNil ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   296
	^ block value:self.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   297
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   298
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   299
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   300
     if it is not the NoHandlerSignal, raise it ...
213
3b56a17534fd *** empty log message ***
claus
parents: 171
diff changeset
   301
     passing the receiver as parameter.
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   302
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   303
    signal ~~ (noHandlerSignal := Signal noHandlerSignal) ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   304
	noHandlerSignal notNil ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   305
	    ^ noHandlerSignal 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   306
		  raiseRequestWith:self 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   307
		       errorString:('unhandled exception: ' , errorString)
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   308
				in:self suspendedContext
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   309
	].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   310
	"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   311
	 mhmh - an error during early startup; noHandlerSignal is
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   312
	 not yet defined.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   313
	"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   314
	^ MiniDebugger enterWithMessage:errorString
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   315
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   316
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   317
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   318
     mhmh - smells like trouble - there is no handler and
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   319
     no per-signal handler block.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   320
     Look for either a per-process emergencyHandlerBlock 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   321
     or the global emergencyHandler (from Exception) ...
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   322
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   323
    Processor notNil ifTrue:[ 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   324
	"care for signal during startup (Processor not yet created)"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   325
	block := Processor activeProcess emergencySignalHandler.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   326
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   327
    block isNil ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   328
	block := Exception emergencyHandler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   329
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   330
    block isNil ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   331
	"care for error during startup (Exception not yet initialized)"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   332
	^ MiniDebugger enterWithMessage:errorString
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   333
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   334
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   335
    "... and call it"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   336
    ^ block value:self.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   337
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   338
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   339
doCallHandler:aHandler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   340
    "call the handler proper - needed an extra method
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   341
     to have a separate returnContext for the rejectBlock.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   342
     (which is historical, and actually no longer needed)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   343
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   344
    rejectBlock := [^ self]. "this will return on reject"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   345
    aHandler value:self.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   346
    "handler fall through - is just like a reject"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   347
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   348
a27a279701f8 Initial revision
claus
parents:
diff changeset
   349
!Exception methodsFor:'handler actions'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   350
a27a279701f8 Initial revision
claus
parents:
diff changeset
   351
reject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   352
    "handler decided not to handle this signal -
a27a279701f8 Initial revision
claus
parents:
diff changeset
   353
     system will look for another handler"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   354
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   355
    rejected := true.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   356
    rejectBlock value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   357
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   358
a27a279701f8 Initial revision
claus
parents:
diff changeset
   359
resume
a27a279701f8 Initial revision
claus
parents:
diff changeset
   360
    "Continue after the raise - the raise returns nil"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   361
a27a279701f8 Initial revision
claus
parents:
diff changeset
   362
    resumeBlock value:nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
   363
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   364
a27a279701f8 Initial revision
claus
parents:
diff changeset
   365
resumeWith:value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   366
    "Continue after the raise - the raise returns value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   367
a27a279701f8 Initial revision
claus
parents:
diff changeset
   368
    resumeBlock value:value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   369
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   370
a27a279701f8 Initial revision
claus
parents:
diff changeset
   371
proceed
a27a279701f8 Initial revision
claus
parents:
diff changeset
   372
    "Continue after the raise - the raise returns nil"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   373
a27a279701f8 Initial revision
claus
parents:
diff changeset
   374
    resumeBlock value:nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
   375
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   376
a27a279701f8 Initial revision
claus
parents:
diff changeset
   377
proceedWith:value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   378
    "Continue after the raise - the raise returns value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   379
a27a279701f8 Initial revision
claus
parents:
diff changeset
   380
    resumeBlock value:value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   381
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   382
a27a279701f8 Initial revision
claus
parents:
diff changeset
   383
return
a27a279701f8 Initial revision
claus
parents:
diff changeset
   384
    "Continue after the handle:do: - the handle:do: returns nil"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   385
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   386
    handlerContext unwind
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   387
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   388
a27a279701f8 Initial revision
claus
parents:
diff changeset
   389
returnWith:value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   390
    "Continue after the handle:do: - the handle:do: returns value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   391
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   392
    handlerContext unwind:value
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   393
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   394
328
claus
parents: 326
diff changeset
   395
returnDoing:aBlock
claus
parents: 326
diff changeset
   396
    "Continue after the handle:do: - the handle:do: returns aBlock value"
claus
parents: 326
diff changeset
   397
claus
parents: 326
diff changeset
   398
    handlerContext unwindThenDo:aBlock
claus
parents: 326
diff changeset
   399
!
claus
parents: 326
diff changeset
   400
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   401
restart
a27a279701f8 Initial revision
claus
parents:
diff changeset
   402
    "restart the handle:do: - usually after some repair work is done
a27a279701f8 Initial revision
claus
parents:
diff changeset
   403
     in handler"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   404
249
claus
parents: 217
diff changeset
   405
    handlerContext unwindAndRestart
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   406
! !