help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] exceptions


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] exceptions
Date: Tue, 31 Oct 2006 20:12:01 +0100
User-agent: Thunderbird 1.5.0.7 (Macintosh/20060909)

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 ]
            ]
     ]

reply via email to

[Prev in Thread] Current Thread [Next in Thread]