Stephen Compall wrote:
Robin Redeker wrote:
So basically the object 1 doesn't understand some exception handling
message and throws an exception itself, which seems to trigger the
handler again. - I would expect that a exception thrown while catching
one (where the catching process fails) would throw that exception so
that it doesn't trigger the same catching process. But maybe i'm just
plain wrong with my expectations.

I spotted a workaround that doesn't mess with the current handler stack:

!Object methodsFor: 'exception handling'!
goodness: anException
    "Answer an integer indicating whether a handler with me as
    the 'on:' argument can handle anException, where a negative
    number means it can't."
    ^-1
! !
Even better:

Object: 1 error: did not understand #goodness:
MessageNotUnderstood(Exception)>>#signal
SmallInteger(Object)>>#doesNotUnderstand:
optimized [] in BlockClosure class>>#exceptionHandlerSearchBlock
[] in CoreException>>#instantiateNextHandler:
MethodContext(ContextPart)>>#scanBacktraceForAttribute:do:
CoreException>>#instantiateNextHandler:
Error(Exception)>>#signal
Error(Exception)>>#signal:
UndefinedObject(Object)>>#error:
optimized [] in UndefinedObject>>#executeStatements
BlockClosure>>#on:do:
UndefinedObject>>#executeStatements
nil

See attached patch (huge because of whitespace changes).

Paolo

--- orig/kernel/BlkClosure.st
+++ mod/kernel/BlkClosure.st
@@ -63,22 +63,26 @@ exceptionHandlerSearchBlock
         | best bestGoodness goodness activeHandlers nested |
         bestGoodness := -1.
         activeHandlers := context at: context numArgs + 1.
-       nested := false.
+        context at: context numArgs + 1 put: -1.
+       nested := activeHandlers = -1.
 
-        1 to: context numArgs - 1 by: 2 do: [ :i |
-            goodness := (context at: i) goodness: signal exception.
-            goodness > -1 ifTrue: [
-                (activeHandlers bitAt: i) = 1 ifTrue: [
-                    "Sorry, this handler is already active..."
-                    nested := true.
-                    goodness := -1.
-                ]
-            ].
-            goodness > bestGoodness ifTrue: [
-                best := i.
-                bestGoodness := goodness.
-            ]
-        ].
+       nested
+           ifFalse: [
+               1 to: context numArgs - 1 by: 2 do: [ :i |
+                   goodness := (context at: i) goodness: signal exception.
+                   goodness > -1 ifTrue: [
+                       (activeHandlers bitAt: i) = 1 ifTrue: [
+                           "Sorry, this handler is already active..."
+                           nested := true.
+                           goodness := -1.
+                       ]
+                   ].
+                   goodness > bestGoodness ifTrue: [
+                       best := i.
+                       bestGoodness := goodness.
+                   ]
+               ]
+           ].
 
         "Now instantiate the best handler we found"
         best isNil
@@ -96,6 +100,7 @@ exceptionHandlerSearchBlock
                #found
             ]
            ifTrue: [
+               context at: context numArgs + 1 put: activeHandlers.
                nested ifTrue: [ #skip ] ifFalse: [ nil ]
            ]
     ]
_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to