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