--- a/GenericException.st Tue Feb 04 21:09:59 2014 +0100
+++ b/GenericException.st Wed Apr 01 10:20:10 2015 +0100
@@ -1,6 +1,6 @@
"
COPYRIGHT (c) 1993 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -11,6 +11,8 @@
"
"{ Package: 'stx:libbasic' }"
+"{ NameSpace: Smalltalk }"
+
Object subclass:#GenericException
instanceVariableNames:'signal parameter messageText suspendedContext raiseContext
handlerContext rejected originator proceedable'
@@ -31,7 +33,7 @@
copyright
"
COPYRIGHT (c) 1993 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -45,16 +47,16 @@
documentation
"
Note:
- The instance based Signal framework is being replaced by
- class based exceptions.
- I.e. what used to be instances of Signal/QuerySignal is beeing
- rewritten into subclasses of Exception/Error/Query and Warning.
- Although the functionality is basically unchanged, the new
- class based exceptions are easier to instanciate (no need for
- creation in a classes initialize method), easier to use (no real
- need for SIgnal-constant accessors) and allow for easier parameter
- passing (not only a single parameter, but allows for individual
- exception subclasses to add additional state).
+ The instance based Signal framework is being replaced by
+ class based exceptions.
+ I.e. what used to be instances of Signal/QuerySignal is beeing
+ rewritten into subclasses of Exception/Error/Query and Warning.
+ Although the functionality is basically unchanged, the new
+ class based exceptions are easier to instanciate (no need for
+ creation in a classes initialize method), easier to use (no real
+ need for SIgnal-constant accessors) and allow for easier parameter
+ passing (not only a single parameter, but allows for individual
+ exception subclasses to add additional state).
GenericException and its subclasses implement the same protocol as Signal.
So class based exceptions may be implemented as subclasses of GenericException.
@@ -67,22 +69,22 @@
The handler block may perform various actions by sending corresponding messages
to the exception object. The following actions are possible:
- reject - don't handle this signal;
- another handler will be searched for,
- upper in the calling hierarchy
-
- proceed - return from the Signal>>raise, with nil as value
-
- proceedWith:val - same, but return val from Signal>>raise
-
- return - return from the Signal>>handle:do:, with nil as value
-
- returnWith:val - same, but return val from Signal>>handle:do:
- (this is also the handler's default,
- if it falls through; taking the handlerBlocks value
- as return value)
-
- restart - restart the Signal>>handle:do:, after repairing
+ reject - don't handle this signal;
+ another handler will be searched for,
+ upper in the calling hierarchy
+
+ proceed - return from the Signal>>raise, with nil as value
+
+ proceedWith:val - same, but return val from Signal>>raise
+
+ return - return from the Signal>>handle:do:, with nil as value
+
+ returnWith:val - same, but return val from Signal>>handle:do:
+ (this is also the handler's default,
+ if it falls through; taking the handlerBlocks value
+ as return value)
+
+ restart - restart the Signal>>handle:do:, after repairing
Via the Exception object, the handler can also query the state of execution:
where the Signal was raised, where the handler is, the signal which caused
@@ -90,18 +92,18 @@
parameter can be passed - the use is signal specific.
[instance variables:]
- signal <Signal> the signal which caused the exception
-
- parameter <Object> a parameter (if any) which was passed when raising
- the signal (only if raised with #raiseWith:aParameter)
-
- messageText <String> an messageText
- (usually the signals own messageText, but sometimes
- changed explicitely in #raiseWith:errorString:)
-
- suspendedContext <Context> the context in which the raise occured
-
- handlerContext <Context> the context of the handler (if any)
+ signal <Signal> the signal which caused the exception
+
+ parameter <Object> a parameter (if any) which was passed when raising
+ the signal (only if raised with #raiseWith:aParameter)
+
+ messageText <String> an messageText
+ (usually the signals own messageText, but sometimes
+ changed explicitely in #raiseWith:errorString:)
+
+ suspendedContext <Context> the context in which the raise occured
+
+ handlerContext <Context> the context of the handler (if any)
In case of an unhandled signal raise, Exceptions EmergenyHandler will be evaluated.
The default emergeny handler will enter the debugger.
@@ -109,53 +111,53 @@
For applications, which do not want Debuggers to come up, other handlers are
possible.
For example, to get the typical C++ behavior, use:
- Exception emergencyHandler:[:ex | Smalltalk exitWithCoreDump]
+ Exception emergencyHandler:[:ex | Smalltalk exitWithCoreDump]
Raising:
- two different raising messages are to be used,
- depending on whether the exception is proceedable or not
-
- For some stupid reason, someone decided that the raise-code checks if
- the raising messages matches to what the signal thinks is its proceedability.
- (i.e. not only do both the sender and the signal itself specify proceedability,
- this is checked by the raise code and a warning is generated if there is a mismatch)
- This used to be even worse (WrongProceedabilityError), but we relaxed this to
- a message sent to stderr.
-
- That means, that PROCEEDABLE signals must be raised with:
- raiseRequest
- and NON-PROCEEDABLE signals must be raised with:
- raise
-
- If you dont know/care as a raiser, you can use
- raiseSignal
- which checks for proceedability and sends the appropriate message.
- (sigh)
+ two different raising messages are to be used,
+ depending on whether the exception is proceedable or not
+
+ For some stupid reason, someone decided that the raise-code checks if
+ the raising messages matches to what the signal thinks is its proceedability.
+ (i.e. not only do both the sender and the signal itself specify proceedability,
+ this is checked by the raise code and a warning is generated if there is a mismatch)
+ This used to be even worse (WrongProceedabilityError), but we relaxed this to
+ a message sent to stderr.
+
+ That means, that PROCEEDABLE signals must be raised with:
+ raiseRequest
+ and NON-PROCEEDABLE signals must be raised with:
+ raise
+
+ If you dont know/care as a raiser, you can use
+ raiseSignal
+ which checks for proceedability and sends the appropriate message.
+ (sigh)
all of the 3 messages above come in various flavours:
- raiseXXX - do not pass any additional parameter;
- default messageText
-
- raiseXXXWith: - pass additional parameter;
- default messageText
-
- raiseXXXErrorString: - do not pass any additional parameter;
- given errorString
-
- raiseXXXWith:errorString:
- - pass any additional parameter;
- AND given errorString
+ raiseXXX - do not pass any additional parameter;
+ default messageText
+
+ raiseXXXWith: - pass additional parameter;
+ default messageText
+
+ raiseXXXErrorString: - do not pass any additional parameter;
+ given errorString
+
+ raiseXXXWith:errorString:
+ - pass any additional parameter;
+ AND given errorString
[see also:]
- Signal SignalSet QuerySignal
- Context Block
- Object DebugView
- (``Exception handling and signals'': programming/exceptions.html)
+ Signal SignalSet QuerySignal
+ Context Block
+ Object DebugView
+ (``Exception handling and signals'': programming/exceptions.html)
[author:]
- Claus Gittinger
+ Claus Gittinger
"
!
@@ -185,7 +187,7 @@
new
"{ Pragma: +inlineNew }"
- ^ self basicNew creator:self.
+ ^ self basicNew initialize creator:self.
"Modified: / 23.7.1999 / 13:53:12 / stefan"
"Created: / 24.7.1999 / 13:21:13 / stefan"
@@ -194,13 +196,14 @@
newException
"{ Pragma: +inlineNew }"
- ^ self basicNew creator:self.
+ ^ self basicNew initialize creator:self.
"Created: / 23.7.1999 / 13:45:49 / stefan"
"Modified: / 24.7.1999 / 13:21:25 / stefan"
! !
-!GenericException class methodsFor:'Compatibility-Squeak'!
+
+!GenericException class methodsFor:'Compatibility-ANSI'!
signal
"raise a signal proceedable or nonproceedable (whichever is right).
@@ -209,6 +212,26 @@
^ self raiseSignal
"Created: / 20-11-2006 / 14:00:09 / cg"
+!
+
+signal:messageText
+ "raise a signal proceedable or nonproceedable (whichever is right).
+ The argument is used as messageText.
+ ANSI/Dolphin compatibility."
+
+ <resource: #skipInDebuggersWalkBack>
+
+ self raiseErrorString:messageText
+!
+
+signalWith:messageText
+ "raise a signal proceedable or nonproceedable (whichever is right).
+ The argument is used as messageText.
+ ANSI compatibility."
+
+ <resource: #skipInDebuggersWalkBack>
+
+ self raiseErrorString:messageText
! !
!GenericException class methodsFor:'accessing'!
@@ -305,17 +328,17 @@
|sig|
self isQuerySignal ifTrue:[
- sig := QuerySignal basicNew.
- mayProceedBoolean ifFalse:[
- 'Exception [warning]: nonProceedable queries do not make sense' infoPrintCR.
- ].
+ sig := QuerySignal basicNew.
+ mayProceedBoolean ifFalse:[
+ 'Exception [warning]: nonProceedable queries do not make sense' infoPrintCR.
+ ].
] ifFalse:[
- sig := Signal basicNew.
+ sig := Signal basicNew.
].
^ sig
- mayProceed:mayProceedBoolean;
- notifierString:NotifierString;
- parent:self
+ mayProceed:mayProceedBoolean;
+ notifierString:NotifierString;
+ parent:self
"Created: / 23.7.1999 / 20:12:43 / stefan"
! !
@@ -347,12 +370,12 @@
|parent|
NotifierString isNil ifTrue:[
- ^ self nameForDescription asString
+ ^ self nameForDescription asString
].
(NotifierString startsWith:Character space) ifTrue:[
- (parent := self parent) notNil ifTrue:[
- ^ parent description, NotifierString
- ].
+ (parent := self parent) notNil ifTrue:[
+ ^ parent description, NotifierString
+ ].
].
^ NotifierString
@@ -386,8 +409,8 @@
s := aSignal parent.
[s notNil] whileTrue:[
- self == s ifTrue:[^ true].
- s := s parent
+ self == s ifTrue:[^ true].
+ s := s parent
].
^ false
@@ -409,7 +432,7 @@
sel := aContext selector.
(sel == #'handle:from:do:'
or:[sel == #'handle:do:']) ifTrue:[
- ^ aContext receiver
+ ^ aContext receiver
].
^ nil
@@ -417,33 +440,33 @@
handlerContextForException:anException in:aContext
"return a handlerContext for anException in the
- contextChain starting with aContext.
+ contextChain starting with aContext.
Returns nil, if there is no handler."
|theContext ex1 con1|
theContext := aContext findExceptional.
[theContext notNil] whileTrue:[
- theContext isRaiseContext ifTrue:[
- "skip all the contexts between the raise and the sender of #handle:do"
- ex1 := theContext receiver. "exception, that has been raised"
- con1 := ex1 handlerContext. "the context of the #handle:do:"
- con1 notNil ifTrue:[
- "handlerContext may be nil, if this is a default action"
- theContext := con1.
- ].
- ex1 := con1 := nil.
- ] ifFalse:[ |r|
- ((r := theContext receiver) notNil
- and:[(r handlerForSignal:anException context:theContext originator:nil) notNil]
- ) ifTrue:[
- "found a handler context"
- ^ theContext
- ].
- ].
- theContext notNil ifTrue:[
- theContext := theContext findSpecialHandle:true raise:true.
- ].
+ theContext isRaiseContext ifTrue:[
+ "skip all the contexts between the raise and the sender of #handle:do"
+ ex1 := theContext receiver. "exception, that has been raised"
+ con1 := ex1 handlerContext. "the context of the #handle:do:"
+ con1 notNil ifTrue:[
+ "handlerContext may be nil, if this is a default action"
+ theContext := con1.
+ ].
+ ex1 := con1 := nil.
+ ] ifFalse:[ |r|
+ ((r := theContext receiver) notNil
+ and:[(r handlerForSignal:anException context:theContext originator:nil) notNil]
+ ) ifTrue:[
+ "found a handler context"
+ ^ theContext
+ ].
+ ].
+ theContext notNil ifTrue:[
+ theContext := theContext findSpecialHandle:true raise:true.
+ ].
].
^ nil
@@ -456,9 +479,9 @@
(theContext selector ~~ #'handle:from:do:'
or:[(theContext argAt:2) == originator]) ifTrue:[
- (self == signal or:[self accepts:signal]) ifTrue:[
- ^ (theContext argAt:1) ? [nil]
- ]
+ (self == signal or:[self accepts:signal]) ifTrue:[
+ ^ (theContext argAt:1) ? [nil]
+ ]
].
^ nil
@@ -473,9 +496,9 @@
sel := context selector.
sel == #handle:do: ifTrue:[
- context argAt:2 put:doBlock.
+ context argAt:2 put:doBlock.
] ifFalse:[sel == #handle:from:do: ifTrue:[
- context argAt:3 put:doBlock.
+ context argAt:3 put:doBlock.
]].
!
@@ -491,7 +514,7 @@
anException isNotification ifTrue:[^ false]. "speed up queries by not traversing the parent chain"
[(signal := signal parent) notNil] whileTrue:[
- self == signal ifTrue:[^ true].
+ self == signal ifTrue:[^ true].
].
^ false
!
@@ -519,7 +542,7 @@
existing Signals."
self == GenericException ifTrue:[
- ^ nil
+ ^ nil
].
^ self superclass
@@ -538,7 +561,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseIn:thisContext sender
+ raiseIn:thisContext sender
"Created: / 23-07-1999 / 14:07:17 / stefan"
"Modified: / 10-08-2010 / 09:30:42 / cg"
@@ -552,8 +575,8 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseErrorString:aString
- in:thisContext sender
+ raiseErrorString:aString
+ in:thisContext sender
"Created: / 23-07-1999 / 14:07:33 / stefan"
"Modified: / 10-08-2010 / 09:34:37 / cg"
@@ -567,22 +590,22 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseErrorString:aString in:aContext
+ raiseErrorString:aString in:aContext
"Created: / 23-07-1999 / 14:07:33 / stefan"
"Modified: / 10-08-2010 / 09:35:37 / cg"
!
-raiseFrom:something
+raiseFrom:something
"raise a signal nonproceedable.
The argument, something is passed both as parameter and originator."
-
+
<context: #return>
<resource: #skipInDebuggersWalkBack>
^ (self newException
- suspendedContext:thisContext sender parameter:something originator:something)
- raise
+ suspendedContext:thisContext sender parameter:something originator:something)
+ raise
"Modified: / 2.5.1996 / 16:36:38 / cg"
"Modified: / 5.3.1998 / 16:49:55 / stefan"
@@ -597,7 +620,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseIn:aContext
+ raiseIn:aContext
"Created: / 27-01-2011 / 17:28:53 / cg"
!
@@ -610,7 +633,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseRequestIn:thisContext sender
+ raiseRequestIn:thisContext sender
"Created: / 23-07-1999 / 14:08:24 / stefan"
"Modified: / 10-08-2010 / 09:37:06 / cg"
@@ -624,21 +647,21 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseRequestErrorString:aString in:thisContext sender
+ raiseRequestErrorString:aString in:thisContext sender
"Modified: / 10-08-2010 / 09:40:38 / cg"
!
-raiseRequestFrom:something
+raiseRequestFrom:something
"raise a signal proceedable.
The argument, something is passed both as parameter and originator."
-
+
<context: #return>
<resource: #skipInDebuggersWalkBack>
^ (self newException
- suspendedContext:thisContext sender parameter:something originator:something)
- raiseRequest
+ suspendedContext:thisContext sender parameter:something originator:something)
+ raiseRequest
"Modified: / 2.5.1996 / 16:36:38 / cg"
"Modified: / 5.3.1998 / 16:52:46 / stefan"
@@ -653,7 +676,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseRequestIn:aContext
+ raiseRequestIn:aContext
"Created: / 27-01-2011 / 17:28:53 / cg"
!
@@ -666,7 +689,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseRequestWith:aParameter in:thisContext sender
+ raiseRequestWith:aParameter in:thisContext sender
"Created: / 23-07-1999 / 14:08:48 / stefan"
"Modified: / 10-08-2010 / 09:57:14 / cg"
@@ -680,7 +703,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseRequestWith:aParameter errorString:aString in:thisContext sender
+ raiseRequestWith:aParameter errorString:aString in:thisContext sender
"Created: / 23-07-1999 / 14:08:57 / stefan"
"Modified: / 10-08-2010 / 09:56:55 / cg"
@@ -696,7 +719,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseRequestWith:aParameter errorString:aString in:aContext
+ raiseRequestWith:aParameter errorString:aString in:aContext
"Created: / 23-07-1999 / 14:09:07 / stefan"
"Modified: / 10-08-2010 / 09:56:36 / cg"
@@ -711,7 +734,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseRequestWith:aParameter in:aContext
+ raiseRequestWith:aParameter in:aContext
"Modified: / 10-08-2010 / 09:56:12 / cg"
!
@@ -724,8 +747,8 @@
<resource: #skipInDebuggersWalkBack>
^ (self newException
- suspendedContext:thisContext sender)
- raiseSignal
+ suspendedContext:thisContext sender)
+ raiseSignal
"Modified: / 10.11.2001 / 15:13:34 / cg"
!
@@ -738,8 +761,8 @@
<resource: #skipInDebuggersWalkBack>
^ (self newException
- suspendedContext:thisContext sender errorString:errorMessage)
- raiseSignal.
+ suspendedContext:thisContext sender errorString:errorMessage)
+ raiseSignal.
"Modified: / 07-08-2004 / 19:24:00 / stefan"
!
@@ -752,8 +775,8 @@
<resource: #skipInDebuggersWalkBack>
^ (self newException
- suspendedContext:thisContext sender parameter:aParameter errorString:errorMessage)
- raiseSignal.
+ suspendedContext:thisContext sender parameter:aParameter errorString:errorMessage)
+ raiseSignal.
"Modified: / 07-08-2004 / 19:10:40 / stefan"
!
@@ -766,8 +789,8 @@
<resource: #skipInDebuggersWalkBack>
^ (self newException
- suspendedContext:thisContext sender errorString:aString)
- raiseSignal.
+ suspendedContext:thisContext sender errorString:aString)
+ raiseSignal.
!
raiseSignalWith:aParameter
@@ -778,8 +801,8 @@
<resource: #skipInDebuggersWalkBack>
^ (self newException
- suspendedContext:thisContext sender parameter:aParameter)
- raiseSignal.
+ suspendedContext:thisContext sender parameter:aParameter)
+ raiseSignal.
!
raiseSignalWith:aParameter errorString:aString
@@ -791,8 +814,8 @@
<resource: #skipInDebuggersWalkBack>
^ (self newException
- suspendedContext:thisContext sender parameter:aParameter errorString:aString)
- raiseSignal.
+ suspendedContext:thisContext sender parameter:aParameter errorString:aString)
+ raiseSignal.
!
raiseWith:aParameter
@@ -803,7 +826,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseWith:aParameter in:thisContext sender
+ raiseWith:aParameter in:thisContext sender
"Created: / 23-07-1999 / 14:09:27 / stefan"
"Modified: / 10-08-2010 / 09:51:11 / cg"
@@ -818,7 +841,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseWith:aParameter errorString:aString in:thisContext sender.
+ raiseWith:aParameter errorString:aString in:thisContext sender.
"Created: / 23-07-1999 / 14:09:36 / stefan"
"Modified: / 10-08-2010 / 09:52:59 / cg"
@@ -835,7 +858,7 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseWith:aParameter errorString:aString in:aContext.
+ raiseWith:aParameter errorString:aString in:aContext.
"Created: / 23-07-1999 / 14:09:46 / stefan"
"Modified: / 10-08-2010 / 09:52:10 / cg"
@@ -851,19 +874,9 @@
<resource: #skipInDebuggersWalkBack>
^ self basicNew
- raiseWith:aParameter in:aContext
+ raiseWith:aParameter in:aContext
"Modified: / 10-08-2010 / 09:52:38 / cg"
-!
-
-signalWith:messageText
- "raise a signal proceedable or nonproceedable (whichever is right).
- The argument is used as messageText.
- ANSI compatibility."
-
- <resource: #skipInDebuggersWalkBack>
-
- self raiseErrorString:messageText
! !
!GenericException class methodsFor:'save evaluation'!
@@ -883,7 +896,7 @@
"
Object messageNotUnderstoodSignal catch:[
- 123 size open
+ 123 size open
]
"
@@ -904,30 +917,30 @@
(especially when packages are sent across a communication channel, and you dont want
partial packages to be generated by user interruptions)."
- |coughtException result|
+ |caughtException result|
self handle:[:ex |
- coughtException isNil ifTrue:[
- coughtException := ex.
- ].
- ex proceedWith:nil
+ caughtException isNil ifTrue:[
+ caughtException := ex.
+ ].
+ ex proceedWith:nil
] do:[
- result := aBlock value.
+ result := aBlock value.
].
- coughtException notNil ifTrue:[
- coughtException suspendedContext:thisContext.
-
- "/ the exception was raised during the execution of aBlock above.
- "/ Raise it now (delayed).
- coughtException raiseSignal.
+ caughtException notNil ifTrue:[
+ caughtException suspendedContext:thisContext.
+
+ "/ the exception was raised during the execution of aBlock above.
+ "/ Raise it now (delayed).
+ caughtException raiseSignal.
].
^ result
"
UserInterrupt deferAfter:[
- Transcript showCR:'1 - now raising, but will be deferred.'.
- UserInterrupt raiseRequestWith:'hello'.
- Transcript showCR:'2 - after the raise, deferred exception will be handled soon.'.
+ Transcript showCR:'1 - now raising, but will be deferred.'.
+ UserInterrupt raiseRequestWith:'hello'.
+ Transcript showCR:'2 - after the raise, deferred exception will be handled soon.'.
].
Transcript showCR:'3 - here after the protected block.'.
"
@@ -938,15 +951,15 @@
evaluate:aBlock ifRaised:exceptionValue
"evaluate the argument, aBlock and return its value.
If the receiver-signal is raised during evaluation, abort
- the evaluation and return the value from exceptionValue.
+ the evaluation and return the value from exceptionValue.
This is similar to the catch & throw mechanism found in other languages"
^ self handle:[:ex | exceptionValue value] do:aBlock.
"
- Object messageNotUnderstoodSignal
- evaluate:[ 123 size open ]
- ifRaised:345
+ Object messageNotUnderstoodSignal
+ evaluate:[ 123 size open ]
+ ifRaised:345
"
!
@@ -967,10 +980,10 @@
"
Object messageNotUnderstoodSignal handle:[:ex |
- 'oops' printNL.
- ex return
+ 'oops' printNL.
+ ex return
] do:[
- 123 size open
+ 123 size open
]
"
@@ -979,10 +992,10 @@
num := 0.
Number divisionByZeroSignal handle:[:ex |
- 'oops' printNL.
- ex return
+ 'oops' printNL.
+ ex return
] do:[
- 123 / num
+ 123 / num
]
"
@@ -1015,17 +1028,17 @@
o1 := 123.
o2 := nil.
Object messageNotUnderstoodSignal
- handle:
- [:ex |
- 'oops' printNL.
- ex proceed
- ]
- from:o1
- do:
- [
- o1 open.
- o2 open
- ]
+ handle:
+ [:ex |
+ 'oops' printNL.
+ ex proceed
+ ]
+ from:o1
+ do:
+ [
+ o1 open.
+ o2 open
+ ]
"
"Created: / 23-07-1999 / 14:06:26 / stefan"
@@ -1044,7 +1057,7 @@
"
Object messageNotUnderstoodSignal ignoreIn:[
- 123 size open
+ 123 size open
]
"
@@ -1096,9 +1109,12 @@
"Modified: / 23.7.1999 / 14:50:11 / stefan"
! !
+
!GenericException methodsFor:'Compatibility-ANSI'!
pass
+ "same as reject - for ANSI compatibility"
+
^ self reject
!
@@ -1136,19 +1152,19 @@
con := suspendedContext.
^ ((1 to:numberOfFrames)
- collect:[:idx |
- |s|
-
- s := con printString.
- con := con sender.
- s
- ]) asStringWith:Character cr.
+ collect:[:idx |
+ |s|
+
+ s := con printString.
+ con := con sender.
+ s
+ ]) asStringWith:Character cr.
"
Error handle:[:ex |
- (ex stackTrace:20) inspect.
+ (ex stackTrace:20) inspect.
] do:[
- self error
+ self error
].
"
! !
@@ -1162,6 +1178,9 @@
!GenericException methodsFor:'Compatibility-V''Age'!
exitWith:value
+ "return with a value.
+ V'AGE compatibility."
+
^ self return:value
"Created: / 28-08-2010 / 14:43:23 / cg"
@@ -1192,7 +1211,12 @@
!
creator
- "return the creator of the exception"
+ "return the creator of the exception.
+ For class based exceptions, that is the exception class;
+ for signals, that is the signal itself.
+ This used to be called signal in earlier versions,
+ but due to the conflict with VSE, Squeak, where signal means 'raise',
+ signal was obsoleted by this method."
signal notNil ifTrue:[^ signal] ifFalse:[^ self class]
!
@@ -1230,23 +1254,23 @@
the object which accepted the actual exception."
handlerContext isNil ifTrue:[
- ^ nil.
+ ^ nil.
].
^ handlerContext receiver exceptionHandlerFor:self in:handlerContext.
"
[
- 2 // 0
+ 2 // 0
] on:Error do:[:ex| ex handler inspect]
[
- 2 // 0
+ 2 // 0
] on:ArithmeticError, Error do:[:ex| ex handler inspect]
[
- 2 // 0
+ 2 // 0
] on:MessageNotUnderstood do:[:ex| ex handler inspect]
- on:Error do:[:ex| ex handler inspect]
+ on:Error do:[:ex| ex handler inspect]
"
!
@@ -1264,7 +1288,7 @@
isResumable
"return true, if the exception is resumable"
- ^ proceedable
+ ^ self mayProceed
"Modified: / 2.3.1998 / 12:20:43 / stefan"
!
@@ -1329,6 +1353,9 @@
!
proceedable:aBoolean
+ "explicitly change the proceedability.
+ Normally this gets initialized from the classes idea of whether this makes sense"
+
proceedable := aBoolean
!
@@ -1356,25 +1383,25 @@
|returnableContext nextContext|
returnableContext := suspendedContext.
- returnableContext canReturn ifFalse:[
- "the context that triggered the exception cannot return.
- This is a fallback: return the the context of the raise*.
- We know, that this context is returnable"
-
- returnableContext := nextContext := raiseContext.
- "find the returnable context that is the nearest in the sender chain
- to suspendedContext...."
- [
- nextContext := nextContext sender.
- nextContext isNil ifTrue:[
- "suspendedContext appears to not exist on sender chain..."
- ^ raiseContext.
- ].
- nextContext canReturn ifTrue:[
- returnableContext := nextContext.
- ].
- nextContext ~~ suspendedContext.
- ] whileTrue.
+ returnableContext canReturn ifFalse:[
+ "the context that triggered the exception cannot return.
+ This is a fallback: return the the context of the raise*.
+ We know, that this context is returnable"
+
+ returnableContext := nextContext := raiseContext.
+ "find the returnable context that is the nearest in the sender chain
+ to suspendedContext...."
+ [
+ nextContext := nextContext sender.
+ nextContext isNil ifTrue:[
+ "suspendedContext appears to not exist on sender chain..."
+ ^ raiseContext.
+ ].
+ nextContext canReturn ifTrue:[
+ returnableContext := nextContext.
+ ].
+ nextContext ~~ suspendedContext.
+ ] whileTrue.
].
^ returnableContext
!
@@ -1383,17 +1410,6 @@
suspendedContext := raisingContext
!
-signal
- "return the signal, that caused the exception.
- Warning and notice: in ANSI, signal means: raise;
- here and in old VW, it is the accessor to create.
- This will change in the near future; please use #creator to get
- the creator. Marked as obsolete, until the change is done!!"
-
- self obsoleteFeatureWarning:'meaning of #signal will change. Use #creator'.
- ^ self creator.
-!
-
suspendedContext
"return the context in which the raise occured"
@@ -1453,8 +1469,8 @@
try per signal handler
"
(handlerBlock := self creator handlerBlock) notNil ifTrue:[
- "... and call it"
- ^ handlerBlock value:self.
+ "... and call it"
+ ^ handlerBlock value:self.
].
^ self noHandler.
@@ -1486,26 +1502,28 @@
|msg|
rejected == true ifTrue:[
- msg := 'unhandled (rejected)'
+ msg := 'unhandled (rejected)'
] ifFalse:[
- msg := 'unhandled'
+ msg := 'unhandled'
].
msg := msg , ' exception: (' , self description , ')'.
self mayProceed ifTrue:[
- ^ NoHandlerError
- raiseRequestWith:self
- errorString:msg
- in:suspendedContext.
+ ^ NoHandlerError
+ raiseRequestWith:self
+ errorString:msg
+ in:suspendedContext.
].
^ NoHandlerError
- raiseWith:self
- errorString:msg
- in:suspendedContext.
+ raiseWith:self
+ errorString:msg
+ in:suspendedContext.
! !
!GenericException methodsFor:'default values'!
defaultResumeValue
+ "the default answer, if no one handles the query and the exception is resumed"
+
^ nil
!
@@ -1516,26 +1534,26 @@
!GenericException methodsFor:'handler actions'!
exit
- "either resume or return - depending on the receivers resumability.
+ "either resume or return - depending on the receiver's resumability.
VW compatibility."
self isResumable ifTrue:[
- self proceedWith:(self defaultResumeValue)
+ self proceedWith:(self defaultResumeValue)
] ifFalse:[
- self return:(self defaultReturnValue)
+ self return:(self defaultReturnValue)
]
"Modified: / 7.9.2001 / 13:28:54 / cg"
!
exit:value
- "either resume or return - depending on the receivers resumability.
+ "either resume or return - depending on the receiver's resumability.
VW compatibility."
self isResumable ifTrue:[
- self proceedWith:value
+ self proceedWith:value
] ifFalse:[
- self return:value
+ self return:value
]
"Created: / 7.9.2001 / 13:29:55 / cg"
@@ -1548,13 +1566,13 @@
self proceedWith:(self defaultResumeValue).
"cg: a strange example:
- there are two cought errors here - can you spot them ?
+ there are two caught errors here - can you spot them ?
Error handle:[:ex|
- 'proceeding' printCR.
- ex proceed
+ 'proceeding' printCR.
+ ex proceed
] do:[
- Error raiseRequest
+ Error raiseRequest
].
"
@@ -1568,9 +1586,9 @@
|con rCon|
(StrictRaising and:[proceedable not]) ifTrue:[
- "proceed from ProceedError to recover from this error"
- ProceedError raiseRequestWith:self.
- proceedable := true.
+ "proceed from ProceedError to recover from this error"
+ ProceedError raiseRequestWith:self.
+ proceedable := true.
].
thisContext evaluateUnwindActionsUpTo:suspendedContext.
@@ -1583,7 +1601,7 @@
"we arrive here, if suspendedContext is not resumable -
resume our raise context ...
... consider this a fallBack kludge, for the case that
- a raising context is not returnable."
+ a raising context is not returnable."
rCon return:value.
@@ -1601,7 +1619,7 @@
con := Context findFirstSpecialHandle:false raise:true.
[con notNil
and:[con receiver ~~ self]] whileTrue:[
- con := con findSpecialHandle:false raise:true.
+ con := con findSpecialHandle:false raise:true.
].
"returning form the doCallXX: signals a reject"
@@ -1610,15 +1628,15 @@
"
Error handle:[:ex |
- '1' printCR.
- ex reject
+ '1' printCR.
+ ex reject
] do:[
- Error handle:[:ex |
- '2' printCR.
- ex reject
- ] do:[
- #() at:1
- ]
+ Error handle:[:ex |
+ '2' printCR.
+ ex reject
+ ] do:[
+ #() at:1
+ ]
]
"
!
@@ -1637,9 +1655,9 @@
|rslt|
ZeroDivide handle:[:ex |
- ex resignalAs:DomainError
+ ex resignalAs:DomainError
] do:[
- rslt := 5 // 0
+ rslt := 5 // 0
].
rslt
"
@@ -1648,9 +1666,9 @@
|rslt|
MessageNotUnderstood handle:[:ex |
- ex resignalAs:Number domainErrorSignal
+ ex resignalAs:Number domainErrorSignal
] do:[
- rslt := 1 perform:#foo
+ rslt := 1 perform:#foo
].
rslt
"
@@ -1660,14 +1678,14 @@
firstTime := true.
ZeroDivide handle:[:ex |
- firstTime ifTrue:[
- Dialog information:'again...'.
- firstTime := false.
- ex resignalAs:ZeroDivide.
- ].
- Dialog information:'arrived here again...'.
+ firstTime ifTrue:[
+ Dialog information:'again...'.
+ firstTime := false.
+ ex resignalAs:ZeroDivide.
+ ].
+ Dialog information:'arrived here again...'.
] do:[
- rslt := 5 // 0
+ rslt := 5 // 0
].
rslt
"
@@ -1691,11 +1709,11 @@
|rslt n|
Error handle:[:ex |
- Transcript showCR:'fixing divisor ...'.
- n := 1.
- ex restart.
+ Transcript showCR:'fixing divisor ...'.
+ n := 1.
+ ex restart.
] do:[
- rslt := 5 / n.
+ rslt := 5 / n.
].
rslt
"
@@ -1728,11 +1746,11 @@
sig := Signal new.
sig handle:[:ex |
- Transcript showCR:'exchanging do-block ...'.
- ex restartDo:[ rslt := 999 ]
+ Transcript showCR:'exchanging do-block ...'.
+ ex restartDo:[ rslt := 999 ]
] do:[
- rslt := 0.
- sig raise
+ rslt := 0.
+ sig raise
].
Transcript showCR:rslt
"
@@ -1741,9 +1759,9 @@
|sig rslt|
Object errorSignal handle:[:ex |
- ex restartDo:[ rslt := 999 ]
+ ex restartDo:[ rslt := 999 ]
] do:[
- rslt := nil foo.
+ rslt := nil foo.
].
Transcript showCR:rslt
@@ -1753,9 +1771,9 @@
|sig rslt|
Object errorSignal handle:[:ex |
- ex restartDo:[ 'handler' printCR. rslt := nil foo ]
+ ex restartDo:[ 'handler' printCR. rslt := nil foo ]
] do:[
- rslt := nil foo.
+ rslt := nil foo.
].
Transcript showCR:rslt
@@ -1860,11 +1878,11 @@
con returnDoing:aBlock
"
- [
- 5 // 0
- ] on:Error do:[:ex|
- ex returnDoing:[self halt. 47*11].
- ]
+ [
+ 5 // 0
+ ] on:Error do:[:ex|
+ ex returnDoing:[self halt. 47*11].
+ ]
"
!
@@ -1884,13 +1902,13 @@
sigDescr := self creator description.
(messageText isNil or:[messageText isString not])
ifTrue:[
- ^ sigDescr
+ ^ sigDescr
].
(messageText startsWith:Character space) ifTrue:[
- ^ sigDescr, messageText.
+ ^ sigDescr, messageText.
].
(messageText endsWith:Character space) ifTrue:[
- ^ messageText, sigDescr.
+ ^ messageText, sigDescr.
].
^ messageText
@@ -1905,7 +1923,7 @@
!
descriptionForDebugger
- "return the description string of the signal which is used in the
+ "return the description string of the signal which is used in the
debugger title area"
^ self description.
@@ -1921,13 +1939,13 @@
"helper for all raiseRequest methods"
self mayProceed ifFalse:[
- StrictRaising ifTrue:[
- "/ proceeding from wrongProceedabilitySignal grants the raiseRequest
- WrongProceedabilityError raiseRequestWith:self creator.
- ] ifFalse:[
- self class name infoPrint.
- ' [warning]: raised with wrong proceedability' infoPrintCR.
- ]
+ StrictRaising ifTrue:[
+ "/ proceeding from wrongProceedabilitySignal grants the raiseRequest
+ WrongProceedabilityError raiseRequestWith:self creator.
+ ] ifFalse:[
+ self class name infoPrint.
+ ' [warning]: raised with wrong proceedability' infoPrintCR.
+ ]
].
"Created: / 10-08-2010 / 09:54:41 / cg"
@@ -1936,7 +1954,7 @@
doCallAction
"call the action proper
- needed an extra method to have a raise-marked context around
- i.e. do not inline this into #doRaise !!
+ i.e. do not inline this into #doRaise !!
(see implementation of #reject and #proceed)."
<context: #return>
@@ -1948,7 +1966,7 @@
doCallHandler:aHandlerBlock
"call the handler proper - if the handler falls through, return the handler's value
- an extra method is needed to have a raise-marked context around.
- i.e. do not inline this into #doRaise !!
+ i.e. do not inline this into #doRaise !!
(see implementation of #reject and #proceed).
- also redefinable (see CascadingNotification)"
@@ -1958,11 +1976,11 @@
|val|
aHandlerBlock argumentCount == 0 ifTrue:[
- "0-arg handler or any object - not interested in the exception argument"
- val := aHandlerBlock value
+ "0-arg handler or any object - not interested in the exception argument"
+ val := aHandlerBlock value
] ifFalse:[
- "1-arg handler - pass myself as exception argument"
- val := aHandlerBlock value:self.
+ "1-arg handler - pass myself as exception argument"
+ val := aHandlerBlock value:self.
].
"handler fall through - is just like a #return:(aHandlerBlock value)"
@@ -1988,16 +2006,16 @@
"is nil a valid originator? If so, we need an extra
instanceVariable to record the originator setting"
originator isNil ifTrue:[
- originator := suspendedContext homeReceiver
+ originator := suspendedContext homeReceiver
].
signal isNil ifTrue:[
- signal := self class
+ signal := self class
] ifFalse:[
- signal isExceptionCreator ifFalse:[
- "not an exception or Signal - there is something wrong here..."
- SignalError raiseWith:signal errorString:'unexpected non-ExceptionCreator in calling context'.
- ]
+ signal isExceptionCreator ifFalse:[
+ "not an exception or Signal - there is something wrong here..."
+ SignalError raiseWith:signal errorString:'unexpected non-ExceptionCreator in calling context'.
+ ]
].
"now, start searching for a handler.
@@ -2008,60 +2026,60 @@
currentContext := suspendedContext findExceptional.
[currentContext notNil] whileTrue:[
- (currentContext isRaiseContext) ifTrue:[
- |ex1 con1|
-
- "skip all the contexts between the raise and the sender of #handle:do"
- ex1 := currentContext receiver. "exception, that has been raised"
- con1 := ex1 handlerContext. "the context of the #handle:do:"
-
- con1 isNil ifTrue:[
- "the handlerContext is nil if an exception's default action is performed.
- Start search at the sending context.
- Maybe we should better treat a default action like a #handle:do:
- at the outest level. But the DebugView currently can't handle this,
- because it tries to raise e.g. AbortOperationRequest even if it has bee invoked
- by e.g. NoHandlerError.
-
- Note that if raiseContext is nil, the exception
- did already return."
-
- (ex1 creator == signal and:[ex1 raiseContext notNil]) ifTrue:[
- "the same exception that has been cought by a default action is raised again.
- don't recurse"
- ^ self noHandler.
- ].
- ] ifFalse:[
- "skip to the raised exception's handleContext"
- currentContext := con1.
- ].
- ex1 := con1 := nil.
- ] ifFalse:[ "currentContext is a handleContext"
- |r handler|
-
- "ask the the receiver of the #handle:do: or #on:do: or whatever- message for the handler.
- nil is returned, if the signal is not accepted"
- r := currentContext receiver. "receiver of #handle:do: or #on:do:"
- (r notNil and:[(handler := r handlerForSignal:signal
- context:currentContext
- originator:originator) notNil]
- ) ifTrue:[
- "call the handler"
-
- handlerContext := currentContext.
- currentContext := nil.
- self doCallHandler:handler.
-
- "if the handler rejects, we arrive here
- continue search for another handler"
- currentContext := handlerContext.
- handler := handlerContext := nil.
- ].
- r := handler := nil.
- ].
- currentContext notNil ifTrue:[
- currentContext := currentContext findSpecialHandle:true raise:true. "search starts at currentContext sender"
- ].
+ (currentContext isRaiseContext) ifTrue:[
+ |ex1 con1|
+
+ "skip all the contexts between the raise and the sender of #handle:do"
+ ex1 := currentContext receiver. "exception, that has been raised"
+ con1 := ex1 handlerContext. "the context of the #handle:do:"
+
+ con1 isNil ifTrue:[
+ "the handlerContext is nil if an exception's default action is performed.
+ Start search at the sending context.
+ Maybe we should better treat a default action like a #handle:do:
+ at the outest level. But the DebugView currently can't handle this,
+ because it tries to raise e.g. AbortOperationRequest even if it has bee invoked
+ by e.g. NoHandlerError.
+
+ Note that if raiseContext is nil, the exception
+ did already return."
+
+ (ex1 creator == signal and:[ex1 raiseContext notNil]) ifTrue:[
+ "the same exception that has been caught by a default action is raised again.
+ don't recurse"
+ ^ self noHandler.
+ ].
+ ] ifFalse:[
+ "skip to the raised exception's handleContext"
+ currentContext := con1.
+ ].
+ ex1 := con1 := nil.
+ ] ifFalse:[ "currentContext is a handleContext"
+ |r handler|
+
+ "ask the the receiver of the #handle:do: or #on:do: or whatever- message for the handler.
+ nil is returned, if the signal is not accepted"
+ r := currentContext receiver. "receiver of #handle:do: or #on:do:"
+ (r notNil and:[(handler := r handlerForSignal:signal
+ context:currentContext
+ originator:originator) notNil]
+ ) ifTrue:[
+ "call the handler"
+
+ handlerContext := currentContext.
+ currentContext := nil.
+ self doCallHandler:handler.
+
+ "if the handler rejects, we arrive here
+ continue search for another handler"
+ currentContext := handlerContext.
+ handler := handlerContext := nil.
+ ].
+ r := handler := nil.
+ ].
+ currentContext notNil ifTrue:[
+ currentContext := currentContext findSpecialHandle:true raise:true. "search starts at currentContext sender"
+ ].
].
"
@@ -2083,7 +2101,7 @@
<context: #return>
raiseContext := thisContext.
- suspendedContext isNil ifTrue:[
+ (suspendedContext isNil or:[handlerContext notNil]) ifTrue:[
suspendedContext := raiseContext sender
].
@@ -2131,7 +2149,8 @@
<context: #return>
raiseContext := thisContext.
- suspendedContext isNil ifTrue:[
+ (suspendedContext isNil or:[handlerContext notNil]) ifTrue:[
+ handlerContext := nil.
suspendedContext := raiseContext sender
].
@@ -2186,9 +2205,9 @@
<context: #return>
- ^ (self
- suspendedContext:thisContext sender parameter:aParameter errorString:aString)
- raiseRequest.
+ ^ (self
+ suspendedContext:thisContext sender parameter:aParameter errorString:aString)
+ raiseRequest.
"Created: / 23.7.1999 / 14:08:57 / stefan"
!
@@ -2237,7 +2256,7 @@
raiseContext := thisContext.
- suspendedContext isNil ifTrue:[
+ (suspendedContext isNil or:[handlerContext notNil]) ifTrue:[
suspendedContext := raiseContext sender
].
proceedable := self mayProceed.
@@ -2253,9 +2272,9 @@
<context: #return>
- ^ (self
- suspendedContext:thisContext sender parameter:aParameter errorString:aString)
- raise.
+ ^ (self
+ suspendedContext:thisContext sender parameter:aParameter errorString:aString)
+ raise.
!
raiseWith:aParameter errorString:aString in:aContext
@@ -2289,6 +2308,17 @@
^ self doRaise
"Created: / 10-08-2010 / 09:50:54 / cg"
+!
+
+signal
+ "return the signal, that caused the exception.
+ Warning and notice: in ANSI, signal means: raise;
+ here and in old VW, it is the accessor to the creator signal/exception.
+
+ This has now changed to be compatible with ANSI/Squeak.
+ Please use #creator to get the creator."
+
+ self raiseSignal.
! !
!GenericException methodsFor:'setup'!
@@ -2357,16 +2387,11 @@
!GenericException class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/GenericException.st,v 1.147 2013-08-24 12:24:21 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/GenericException.st,v 1.160 2015-01-12 16:07:53 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/GenericException.st,v 1.147 2013-08-24 12:24:21 cg Exp $'
-!
-
-version_HG
-
- ^ '$Changeset: <not expanded> $'
+ ^ '$Header: /cvs/stx/stx/libbasic/GenericException.st,v 1.160 2015-01-12 16:07:53 cg Exp $'
! !