#REFACTORING by cg
class: Block
changed:
#exceptionHandlerFor:in:
#handlerForSignal:context:originator:
common code refactoring
--- a/Block.st Tue Mar 20 22:06:14 2018 +0100
+++ b/Block.st Tue Mar 20 22:07:03 2018 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -666,7 +668,6 @@
"Created: / 28-08-2010 / 14:41:15 / cg"
! !
-
!Block methodsFor:'accessing'!
home
@@ -867,7 +868,7 @@
micros < 1000 ifTrue:[
"/ too stupid: many fonts do not have a mu,
"/ so I output it as us here.
- Transcript show:micros; show:' µs'.
+ Transcript show:micros; show:' µs'.
] ifFalse:[
micros < 100000 ifTrue:[
millis := (micros / 1000.0) asFixedPointRoundedToScale:2.
@@ -2540,142 +2541,86 @@
"answer the exceptionHandler (the Error or signal) for anException from aContext."
aContext selector == #on:do:on:do: ifTrue:[
- |exceptionCreator exceptionHandlerInContext|
-
- exceptionCreator := anException creator.
- exceptionHandlerInContext := aContext argAt:1.
- exceptionHandlerInContext isExceptionHandler ifFalse:[
- exceptionHandlerInContext isNil ifTrue:[
- 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
- ] ifFalse:[
- (exceptionHandlerInContext isBehavior
- and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
- "If the exception class is still autoloaded,
- it does not accept our exception. Raising the exception would load the class"
- ^ nil
- ] ifFalse:[
- 'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
- ]
- ].
- aContext fullPrintString errorPrintCR.
- self breakPoint:#cg.
- ^ nil.
- ].
- (exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[
- ^ exceptionHandlerInContext.
- ].
-
- exceptionHandlerInContext := aContext argAt:3.
- exceptionHandlerInContext isExceptionHandler ifFalse:[
- exceptionHandlerInContext isNil ifTrue:[
- 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
- ] ifFalse:[
- (exceptionHandlerInContext isBehavior
- and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
- "If the exception class is still autoloaded,
- it does not accept our exception. Raising the exception would load the class"
- ^ nil
- ] ifFalse:[
- 'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
- ]
- ].
- aContext fullPrintString errorPrintCR.
- self breakPoint:#cg.
- ^ nil.
- ].
- (exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[
- ^ exceptionHandlerInContext.
- ].
- ^ nil.
+ |exceptionCreator exceptionHandlerInContext|
+
+ exceptionCreator := anException creator.
+ exceptionHandlerInContext := aContext argAt:1.
+ exceptionHandlerInContext isExceptionHandler ifFalse:[
+ GenericException printBadExceptionHandler:exceptionHandlerInContext in:aContext.
+ ^ nil.
+ ].
+ (exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[
+ ^ exceptionHandlerInContext.
+ ].
+
+ exceptionHandlerInContext := aContext argAt:3.
+ exceptionHandlerInContext isExceptionHandler ifFalse:[
+ GenericException printBadExceptionHandler:exceptionHandlerInContext in:aContext.
+ ^ nil.
+ ].
+ (exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[
+ ^ exceptionHandlerInContext.
+ ].
+ ^ nil.
].
"aContext selector must be #on:do: , #on:do:ensure: or #valueWithExceptionHandler:"
^ aContext argAt:1.
!
-handlerForSignal:exceptionCreator context:theContext originator:originator
+handlerForSignal:exceptionCreator context:aContext originator:originator
"answer the handler block for the exceptionCreator from originator.
The handler block is retrieved from aContext.
Answer nil if the exceptionCreator is not handled."
|selector exceptionHandlerInContext|
- selector := theContext selector.
+ selector := aContext selector.
(selector == #on:do:
or:[ selector == #on:do:ensure:
or:[ selector == #on:do:ifCurtailed: ]]
) ifTrue:[
- exceptionHandlerInContext := theContext argAt:1.
+ exceptionHandlerInContext := aContext argAt:1.
exceptionHandlerInContext isExceptionHandler ifFalse:[
- exceptionHandlerInContext isNil ifTrue:[
- 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
- ] ifFalse:[(exceptionHandlerInContext isBehavior
- and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
- "If the exception class is still autoloaded,
- it does not accept our exception. Raising the exception would load the class"
- ^ nil
- ] ifFalse:[
- 'Block [warning]: non-ExceptionHandler in on:do:-context' errorPrintCR.
- ]].
- theContext fullPrint.
+ GenericException printBadExceptionHandler:exceptionHandlerInContext in:aContext.
^ nil.
].
(exceptionHandlerInContext == exceptionCreator
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[
selector == #on:do:ifCurtailed: ifTrue:[
- theContext unmarkForUnwind. "if there is a handler, no unwind block has to be performed"
+ aContext unmarkForUnwind. "if there is a handler, no unwind block has to be performed"
].
- ^ (theContext argAt:2) ? [nil].
+ ^ (aContext argAt:2) ? [nil].
].
^ nil
].
selector == #on:do:on:do: ifTrue:[
- exceptionHandlerInContext := theContext argAt:1.
+ exceptionHandlerInContext := aContext argAt:1.
exceptionHandlerInContext isExceptionHandler ifFalse:[
- exceptionHandlerInContext isNil ifTrue:[
- 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
- ] ifFalse:[(exceptionHandlerInContext isBehavior
- and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
- "If the exception class is still autoloaded,
- it does not accept our exception. Raising the exception would load the class"
- ^ nil
- ] ifFalse:[
- 'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
- ]].
- theContext fullPrint.
+ GenericException printBadExceptionHandler:exceptionHandlerInContext in:aContext.
^ nil.
].
(exceptionHandlerInContext == exceptionCreator
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[
- ^ (theContext argAt:2) ? [nil].
+ ^ (aContext argAt:2) ? [nil].
].
- exceptionHandlerInContext := theContext argAt:3.
+ exceptionHandlerInContext := aContext argAt:3.
exceptionHandlerInContext isExceptionHandler ifFalse:[
- exceptionHandlerInContext isNil ifTrue:[
- 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
- ] ifFalse:[(exceptionHandlerInContext isBehavior
- and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
- "If the exception class is still autoloaded,
- it does not accept our exception. Raising the exception would load the class"
- ^ nil
- ] ifFalse:[
- 'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
- ]].
- theContext fullPrint.
+ GenericException printBadExceptionHandler:exceptionHandlerInContext in:aContext.
^ nil.
].
(exceptionHandlerInContext == exceptionCreator
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[
- ^ (theContext argAt:4) ? [nil].
+ ^ (aContext argAt:4) ? [nil].
].
^ nil
].
selector == #valueWithExceptionHandler: ifTrue:[
- ^ (theContext argAt:1) handlerForSignal:exceptionCreator.
+ ^ (aContext argAt:1) handlerForSignal:exceptionCreator.
].
"/ mhmh - should not arrive here