Exception.st
author claus
Sat, 22 Jul 1995 21:25:26 +0200
changeset 362 4131e87e79ec
parent 345 cf2301210c47
child 367 a2114577b799
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
362
claus
parents: 345
diff changeset
    16
				rejected originator
171
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
362
claus
parents: 345
diff changeset
    27
$Header: /cvs/stx/stx/libbasic/Exception.st,v 1.22 1995-07-22 19:22:18 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
"
362
claus
parents: 345
diff changeset
    48
$Header: /cvs/stx/stx/libbasic/Exception.st,v 1.22 1995-07-22 19:22:18 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
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    61
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    62
	proceed         - return from the Signal>>raise, with nil as value
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    63
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    64
	proceedWith:val - same, but return val from Signal>>raise
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    66
	return          - return from the Signal>>handle:do:, with nil as value
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    67
362
claus
parents: 345
diff changeset
    68
	returnWith:val  - same, but return val from Signal>>handle:do:
claus
parents: 345
diff changeset
    69
			  (this is also the handlers default, 
claus
parents: 345
diff changeset
    70
			   if it falls through; taking the handlerBlocks value
claus
parents: 345
diff changeset
    71
			   as return value)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    73
	restart         - restart the Signal>>handle:do:, after repairing
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    75
    Via the Exception object, the handler can also query the state of execution:
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    76
    where the Signal was raised, where the handler is, the signal which caused
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    77
    the error and the errorString passed when the signal was raised. Also, an optional
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    78
    parameter can be passed - the use is signal specific.:
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
    79
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    80
    instance variables:
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    81
	signal           <Signal>     the signal which caused the exception
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    82
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    83
	parameter        <Object>     a parameter (if any) which was passed when raising
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    84
				      the signal (only if raised with #raiseWith:aParameter)
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    85
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    86
	errorString      <String>     an errorString 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    87
				      (usually the signals own errorString, but sometimes
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    88
				       changed explicitely in #raiseWith:errorString:)
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
    89
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    90
	suspendedContext <Context>    the context in which the raise occured
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    91
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    92
	handlerContext   <Context>    the context of the handler (if any)
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    93
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    94
	resumeBlock      <Block>      private to the exception; needed to perform resume action
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
    95
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
    96
	rejectBlock      <Block>      private to the exception; needed to perform reject action
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
    97
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
    98
    In case of an unhandled signal raise, Exceptions EmergenyHandler will be evaluated. 
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    99
    The default emergeny handler will enter the debugger.
142
c7844287bddf *** empty log message ***
claus
parents: 130
diff changeset
   100
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   101
    For applications, which do not want Debuggers to come up, other handlers are
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   102
    possible.
362
claus
parents: 345
diff changeset
   103
    For example, to get the typical C++ behavior, use:
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   104
	Exception emergencyHandler:[:ex | Smalltalk exitWithCoreDump]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   105
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   106
    Class variables:
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   107
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   108
	EmergencyHandler <Block>    this block is evaluated, if no handler was defined
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   109
				    for a signal (i.e. this one is responsible for the
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   110
				    unhandled exception debugger).
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   111
				    Having this being a block allows to globally catch
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   112
				    these errors - even when no enclosing handler-scope
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   113
				    around the erronous code exists.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   114
				    (as the catch/through does).
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   115
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   116
	RecursiveExceptionSignal
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   117
			 <Signal>   raised when within a handler for some signal,
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   118
				    th same signal is raised again.
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   119
"
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   120
! !
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   121
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   122
!Exception class methodsFor:'initialization'!
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   123
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   124
initialize 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   125
    "setup the signal used to handle unhandled signals"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   126
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   127
    RecursiveExceptionSignal isNil ifTrue:[
302
1f76060d58a4 *** empty log message ***
claus
parents: 255
diff changeset
   128
	RecursiveExceptionSignal := ErrorSignal newSignalMayProceed:false.
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   129
	RecursiveExceptionSignal nameClass:self message:#recursiveExceptionSignal.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   130
	RecursiveExceptionSignal notifierString:'recursive signal raise in handler'
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   131
    ]
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   132
! !
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   133
345
claus
parents: 328
diff changeset
   134
!Exception class methodsFor:'Signal constants'!
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   135
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   136
recursiveExceptionSignal
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   137
    "return the signal used to handle recursive signals in the handlers"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   138
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   139
    ^ RecursiveExceptionSignal
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   140
! !
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   141
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   142
!Exception class methodsFor:'defaults'!
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   143
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   144
emergencyHandler
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   145
    "return the handler used for unhandled exceptions"
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   146
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   147
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   148
     set it up, when called the first time
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   149
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   150
    EmergencyHandler isNil ifTrue:[
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   151
	EmergencyHandler := [:ex |
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   152
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   153
	     sending it to the signal allows per-signal specific
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   154
	     debuggers to be implemented in the future
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   155
	     (for example, segv in primitive code could show things 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   156
	      on the C-level ..)
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   157
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   158
	    (ex signal) enterDebuggerWith:ex message:(ex errorString).
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   159
	]
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   160
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   161
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   162
    ^ EmergencyHandler
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   163
!
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   164
130
e09411db2573 emergencyhandler is now a one-arg-block
claus
parents: 92
diff changeset
   165
emergencyHandler:aOneArgBlock
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   166
    "set the handler used for unhandled exceptions"
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   167
130
e09411db2573 emergencyhandler is now a one-arg-block
claus
parents: 92
diff changeset
   168
    EmergencyHandler := aOneArgBlock
362
claus
parents: 345
diff changeset
   169
claus
parents: 345
diff changeset
   170
    "ST-80 behavior of first showing a notifier:
claus
parents: 345
diff changeset
   171
     (I prefer to get right into the debugger, though)
claus
parents: 345
diff changeset
   172
claus
parents: 345
diff changeset
   173
     Exception
claus
parents: 345
diff changeset
   174
	emergencyHandler:
claus
parents: 345
diff changeset
   175
	    [:ex | self notify:ex errorString ]
claus
parents: 345
diff changeset
   176
    "
claus
parents: 345
diff changeset
   177
claus
parents: 345
diff changeset
   178
    "automatically aborting current operation, on error:
claus
parents: 345
diff changeset
   179
     (may be useful for end-user apps; make certain, 
claus
parents: 345
diff changeset
   180
      you have abortSignal handlers at appropriate places)
claus
parents: 345
diff changeset
   181
claus
parents: 345
diff changeset
   182
     Exception
claus
parents: 345
diff changeset
   183
	emergencyHandler:
claus
parents: 345
diff changeset
   184
	    [:ex | Object abortSignal raise. ex return. ]
claus
parents: 345
diff changeset
   185
    "
claus
parents: 345
diff changeset
   186
claus
parents: 345
diff changeset
   187
    "finally, traditional language system behavior; dump core ;-)
claus
parents: 345
diff changeset
   188
claus
parents: 345
diff changeset
   189
     Exception
claus
parents: 345
diff changeset
   190
	emergencyHandler:
claus
parents: 345
diff changeset
   191
	    [:ex | Smalltalk exitWithCoreDump. ]
claus
parents: 345
diff changeset
   192
    "
claus
parents: 345
diff changeset
   193
! !
claus
parents: 345
diff changeset
   194
claus
parents: 345
diff changeset
   195
!Exception class methodsFor:'instance creation'!
claus
parents: 345
diff changeset
   196
claus
parents: 345
diff changeset
   197
signal:aSignal parameter:aParameter errorString:aString suspendedContext:sContext originator:origin
claus
parents: 345
diff changeset
   198
    "create a new instance and set the fields in preparation for a raise.
claus
parents: 345
diff changeset
   199
     - only to be sent from the signal when raising"
claus
parents: 345
diff changeset
   200
claus
parents: 345
diff changeset
   201
    ^ (self new)
claus
parents: 345
diff changeset
   202
	signal:aSignal 
claus
parents: 345
diff changeset
   203
	parameter:aParameter 
claus
parents: 345
diff changeset
   204
	errorString:aString 
claus
parents: 345
diff changeset
   205
	suspendedContext:sContext 
claus
parents: 345
diff changeset
   206
	originator:origin.
claus
parents: 345
diff changeset
   207
! 
claus
parents: 345
diff changeset
   208
claus
parents: 345
diff changeset
   209
signal:aSignal parameter:aParameter errorString:aString suspendedContext:sContext
claus
parents: 345
diff changeset
   210
    "create a new instance and set the fields in preparation for a raise.
claus
parents: 345
diff changeset
   211
     - only to be sent from the signal when raising"
claus
parents: 345
diff changeset
   212
claus
parents: 345
diff changeset
   213
    ^ (self new)
claus
parents: 345
diff changeset
   214
	signal:aSignal 
claus
parents: 345
diff changeset
   215
	parameter:aParameter 
claus
parents: 345
diff changeset
   216
	errorString:aString 
claus
parents: 345
diff changeset
   217
	suspendedContext:sContext 
claus
parents: 345
diff changeset
   218
	originator:(sContext receiver).
12
8e03bd717355 *** empty log message ***
claus
parents: 3
diff changeset
   219
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   220
a27a279701f8 Initial revision
claus
parents:
diff changeset
   221
!Exception methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   222
a27a279701f8 Initial revision
claus
parents:
diff changeset
   223
signal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   224
    "return the signal, that caused the exception"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   225
a27a279701f8 Initial revision
claus
parents:
diff changeset
   226
    ^ signal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   227
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   228
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   229
parameter
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   230
    "return the parameter passsed with the signal raise
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   231
     (or nil, if there was none)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
a27a279701f8 Initial revision
claus
parents:
diff changeset
   233
    ^ parameter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   234
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   235
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   236
errorString 
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   237
    "return the errorString passsed with the signal raise
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   238
     (or nil, if there was none)"
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   239
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   240
    ^ errorString
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   241
!
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   242
362
claus
parents: 345
diff changeset
   243
originator 
claus
parents: 345
diff changeset
   244
    "return the originator passsed with the signal raise
claus
parents: 345
diff changeset
   245
     (or nil, if there was none)"
claus
parents: 345
diff changeset
   246
claus
parents: 345
diff changeset
   247
    ^ originator
claus
parents: 345
diff changeset
   248
!
claus
parents: 345
diff changeset
   249
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   250
handlerContext
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   251
    "return the context of the handler"
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   252
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   253
    ^ handlerContext
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   254
!
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   255
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   256
suspendedContext
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   257
    "return the context in which the raise occured"
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   258
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   259
    ^ suspendedContext
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   260
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   261
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   262
rejected
362
claus
parents: 345
diff changeset
   263
    "return true, if any other of the exceptions handlers has rejected 
claus
parents: 345
diff changeset
   264
     Uncertain, if this is really interresting to anybody.
claus
parents: 345
diff changeset
   265
     This is only valid during handler execution.
claus
parents: 345
diff changeset
   266
     (i.e. an outer handler can find out, if any other handler has already
claus
parents: 345
diff changeset
   267
     rejected).
claus
parents: 345
diff changeset
   268
     "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   269
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   270
    ^ rejected
362
claus
parents: 345
diff changeset
   271
!
claus
parents: 345
diff changeset
   272
claus
parents: 345
diff changeset
   273
willProceed
claus
parents: 345
diff changeset
   274
    "return true, if the exception is proceedable"
claus
parents: 345
diff changeset
   275
claus
parents: 345
diff changeset
   276
    ^ resumeBlock notNil
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
a27a279701f8 Initial revision
claus
parents:
diff changeset
   279
!Exception methodsFor:'setup'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   280
362
claus
parents: 345
diff changeset
   281
signal:aSignal parameter:aParameter errorString:aString suspendedContext:sContext originator:origin
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   282
    "set the fields usable for inspection by the handler
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   283
     - only to be sent from the signal when raising"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   284
44
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   285
    signal := aSignal.
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   286
    parameter := aParameter.
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   287
    errorString := aString.
b262907c93ea *** empty log message ***
claus
parents: 12
diff changeset
   288
    suspendedContext := sContext.
362
claus
parents: 345
diff changeset
   289
    originator := origin.
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   290
! !
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   291
217
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   292
!Exception methodsFor:'raising'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   293
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   294
raise
362
claus
parents: 345
diff changeset
   295
    "actually raise a nonproceedable exception.
claus
parents: 345
diff changeset
   296
     For now, same as #raiseRequest (always proceedable)."
claus
parents: 345
diff changeset
   297
claus
parents: 345
diff changeset
   298
    resumeBlock := [:value | ^ value].
claus
parents: 345
diff changeset
   299
    ^ self evaluateHandler
claus
parents: 345
diff changeset
   300
!
claus
parents: 345
diff changeset
   301
claus
parents: 345
diff changeset
   302
raiseRequest
claus
parents: 345
diff changeset
   303
    "actually raise a proceedable exception."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   304
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   305
    resumeBlock := [:value | ^ value].
217
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   306
    ^ self evaluateHandler
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   307
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   308
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   309
evaluateHandler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   310
    "search through the context-calling chain for a 'handle:do:'-context 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   311
     to the raising signal a parent of it or a SignalSet which includes 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   312
     the raising signal.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   313
     If found, take the contexts 2nd argument (the handler) and evaluate
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   314
     it with the receiver exception as argument.
217
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   315
     If no handler is found, try per signal handler, or
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   316
     per process handler (if its the noHandlerSignal).
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   317
     Finally fall back to Exceptions emergencyHandler, which is always
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   318
     available and enters the debugger."
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   319
362
claus
parents: 345
diff changeset
   320
    |con block noHandlerSignal any msg sel|
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   321
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   322
    con := thisContext sender.  "the raise-context"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   323
    con := con sender.          "the signal raise context"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   324
    con isRecursive ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   325
	"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   326
	 mhmh - an error while in a handler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   327
	"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   328
	((signal == RecursiveExceptionSignal)
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   329
	or:[RecursiveExceptionSignal isNil]) ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   330
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   331
	     ... either while handling RecursiveExceptionSignal
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   332
	     or at startup when RecursiveExceptionSignal is not yet
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   333
	     created -
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   334
	     - go immediately into the debugger.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   335
	    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   336
	    ^ self enterDebuggerWith:self
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   337
			     message:'recursive signal raise'
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   338
	].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   339
	^ RecursiveExceptionSignal 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   340
	    raiseRequestWith:self 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   341
		 errorString:('recursive signal raise: ' , errorString)
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   342
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   343
362
claus
parents: 345
diff changeset
   344
    any := false.
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   345
    [con notNil] whileTrue:[
362
claus
parents: 345
diff changeset
   346
	con isBlockContext ifFalse:[
claus
parents: 345
diff changeset
   347
	    (((sel := con selector) == #'handle:do:') 
claus
parents: 345
diff changeset
   348
	    or:[((sel == #'handle:from:do:')
claus
parents: 345
diff changeset
   349
		and:[(con args at:2) == originator])]) ifTrue:[
claus
parents: 345
diff changeset
   350
		"
claus
parents: 345
diff changeset
   351
		 if this is the Signal>>handle:do: context
claus
parents: 345
diff changeset
   352
		 or a SignalSet>>handle:do: context with self in it,
claus
parents: 345
diff changeset
   353
		 call the handler
claus
parents: 345
diff changeset
   354
		"
claus
parents: 345
diff changeset
   355
		(con receiver accepts:signal) ifTrue:[
claus
parents: 345
diff changeset
   356
		    "call the handler"
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   357
362
claus
parents: 345
diff changeset
   358
		    handlerContext := con.
claus
parents: 345
diff changeset
   359
		    any := true.
claus
parents: 345
diff changeset
   360
		    self doCallHandler:(con args at:1).
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   361
362
claus
parents: 345
diff changeset
   362
		    "if the handler rejects, we arrive here"
claus
parents: 345
diff changeset
   363
		    "continue search for another handler"
claus
parents: 345
diff changeset
   364
		].
claus
parents: 345
diff changeset
   365
	    ]
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   366
	].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   367
	con := con sender
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   368
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   369
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   370
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   371
     we arrive here, if either no handler was found, or none of the
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   372
     handlers did a return (i.e. every handler rejected or fell through).
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   373
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   374
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   375
     try per signal handler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   376
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   377
    (block := signal handlerBlock) notNil ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   378
	^ block value:self.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   379
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   380
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   381
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   382
     if it is not the NoHandlerSignal, raise it ...
213
3b56a17534fd *** empty log message ***
claus
parents: 171
diff changeset
   383
     passing the receiver as parameter.
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   384
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   385
    signal ~~ (noHandlerSignal := Signal noHandlerSignal) ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   386
	noHandlerSignal notNil ifTrue:[
362
claus
parents: 345
diff changeset
   387
	    any ifTrue:[
claus
parents: 345
diff changeset
   388
		msg := 'unhandled (rejected)'
claus
parents: 345
diff changeset
   389
	    ] ifFalse:[
claus
parents: 345
diff changeset
   390
		msg := 'unhandled'
claus
parents: 345
diff changeset
   391
	    ].
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   392
	    ^ noHandlerSignal 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   393
		  raiseRequestWith:self 
362
claus
parents: 345
diff changeset
   394
		       errorString:(msg , ' exception: ' , errorString)
255
2b2c5c0facab *** empty log message ***
claus
parents: 249
diff changeset
   395
				in:self suspendedContext
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   396
	].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   397
	"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   398
	 mhmh - an error during early startup; noHandlerSignal is
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   399
	 not yet defined.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   400
	"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   401
	^ MiniDebugger enterWithMessage:errorString
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   402
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   403
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   404
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   405
     mhmh - smells like trouble - there is no handler and
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   406
     no per-signal handler block.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   407
     Look for either a per-process emergencyHandlerBlock 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   408
     or the global emergencyHandler (from Exception) ...
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   409
    "
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   410
    Processor notNil ifTrue:[ 
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   411
	"care for signal during startup (Processor not yet created)"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   412
	block := Processor activeProcess emergencySignalHandler.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   413
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   414
    block isNil ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   415
	block := Exception emergencyHandler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   416
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   417
    block isNil ifTrue:[
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   418
	"care for error during startup (Exception not yet initialized)"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   419
	^ MiniDebugger enterWithMessage:errorString
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   420
    ].
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   421
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   422
    "... and call it"
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   423
    ^ block value:self.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   424
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   425
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   426
doCallHandler:aHandler
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   427
    "call the handler proper - needed an extra method
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   428
     to have a separate returnContext for the rejectBlock.
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   429
     (which is historical, and actually no longer needed)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   430
362
claus
parents: 345
diff changeset
   431
    |val|
claus
parents: 345
diff changeset
   432
171
129f0e2e23df handling now in Exception
claus
parents: 142
diff changeset
   433
    rejectBlock := [^ self]. "this will return on reject"
362
claus
parents: 345
diff changeset
   434
    val := aHandler value:self.
claus
parents: 345
diff changeset
   435
    "
claus
parents: 345
diff changeset
   436
     handler fall through - is just like a returnWith:blocks-value
claus
parents: 345
diff changeset
   437
    "
claus
parents: 345
diff changeset
   438
    self returnWith:val
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   439
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   440
a27a279701f8 Initial revision
claus
parents:
diff changeset
   441
!Exception methodsFor:'handler actions'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   442
a27a279701f8 Initial revision
claus
parents:
diff changeset
   443
reject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   444
    "handler decided not to handle this signal -
a27a279701f8 Initial revision
claus
parents:
diff changeset
   445
     system will look for another handler"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   446
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   447
    rejected := true.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   448
    rejectBlock value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   449
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   450
a27a279701f8 Initial revision
claus
parents:
diff changeset
   451
resume
a27a279701f8 Initial revision
claus
parents:
diff changeset
   452
    "Continue after the raise - the raise returns nil"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   453
362
claus
parents: 345
diff changeset
   454
    resumeBlock notNil ifTrue:[resumeBlock value:nil]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   455
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   456
a27a279701f8 Initial revision
claus
parents:
diff changeset
   457
resumeWith:value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   458
    "Continue after the raise - the raise returns value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   459
362
claus
parents: 345
diff changeset
   460
    resumeBlock notNil ifTrue:[resumeBlock value:value]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   461
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   462
a27a279701f8 Initial revision
claus
parents:
diff changeset
   463
proceed
a27a279701f8 Initial revision
claus
parents:
diff changeset
   464
    "Continue after the raise - the raise returns nil"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   465
362
claus
parents: 345
diff changeset
   466
    resumeBlock notNil ifTrue:[resumeBlock value:nil]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   467
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   468
a27a279701f8 Initial revision
claus
parents:
diff changeset
   469
proceedWith:value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   470
    "Continue after the raise - the raise returns value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   471
362
claus
parents: 345
diff changeset
   472
    resumeBlock notNil ifTrue:[resumeBlock value:value]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   473
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   474
a27a279701f8 Initial revision
claus
parents:
diff changeset
   475
return
a27a279701f8 Initial revision
claus
parents:
diff changeset
   476
    "Continue after the handle:do: - the handle:do: returns nil"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   477
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   478
    handlerContext unwind
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   479
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   480
a27a279701f8 Initial revision
claus
parents:
diff changeset
   481
returnWith:value
a27a279701f8 Initial revision
claus
parents:
diff changeset
   482
    "Continue after the handle:do: - the handle:do: returns value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   483
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   484
    handlerContext unwind:value
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   485
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   486
328
claus
parents: 326
diff changeset
   487
returnDoing:aBlock
claus
parents: 326
diff changeset
   488
    "Continue after the handle:do: - the handle:do: returns aBlock value"
claus
parents: 326
diff changeset
   489
claus
parents: 326
diff changeset
   490
    handlerContext unwindThenDo:aBlock
claus
parents: 326
diff changeset
   491
!
claus
parents: 326
diff changeset
   492
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   493
restart
a27a279701f8 Initial revision
claus
parents:
diff changeset
   494
    "restart the handle:do: - usually after some repair work is done
a27a279701f8 Initial revision
claus
parents:
diff changeset
   495
     in handler"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   496
249
claus
parents: 217
diff changeset
   497
    handlerContext unwindAndRestart
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   498
! !