diff --git a/stix/kernel/Context.st b/stix/kernel/Context.st index 688a09c..4d6f18c 100644 --- a/stix/kernel/Context.st +++ b/stix/kernel/Context.st @@ -302,6 +302,12 @@ thisContext isHandlerContext dump. self signal. } + #method pass + { + ## pass the exception to the outer context + ## TODO: + } + #method isHandled { ^self handlerContext notNil @@ -309,7 +315,7 @@ thisContext isHandlerContext dump. #method handle { - self return: (self.handlerContext handlerBlock value: self) + Processor return: (self.handlerContext handlerBlock value: self) to: (self.handlerContext sender) } #method notHandled @@ -322,28 +328,23 @@ Processor activeProcess terminate. #method handlerContext { (self.handlerContext notNil) ifTrue: [ ^self.handlerContext ]. - ^self handlerContextStartingFrom: self.signalContext sender. + self.handlerContext := self findHandlerContextStartingFrom: self.signalContext. + ^self.handlerContext. } - #method handlerContextStartingFrom: aContext + #method findHandlerContextStartingFrom: aContext { ## Find exception handling context starting from a given context - | ctx | ctx := aContext. [ ctx notNil ] whileTrue: [ - (ctx handles: self) ifTrue: [ ^self.handlerContext := ctx ]. + (ctx handles: self) ifTrue: [ ^ ctx ]. ctx := ctx sender ]. ^nil } - - #method return: anObject - { - Processor return: anObject to: (self.handlerContext parent) - } } #class NoSuchMessageException(Exception) diff --git a/stix/kernel/test-011.st b/stix/kernel/test-011.st index 395b7eb..ccfc3ea 100644 --- a/stix/kernel/test-011.st +++ b/stix/kernel/test-011.st @@ -37,8 +37,22 @@ #class MyObject(TestObject) { + #method(#class) main2 + { + | k | + k := ['this is test-011' dump. Exception signal. 8888 dump. ] + on: Exception do: [ :ex | 'Exception occurred' dump. ex dump. 'Getting back to' dump. 80. ex pass ]. + + k dump. + 'END OF test-011' dump. + } + #method(#class) main { - ['this is test-011' dump. Exception signal. ] on: Exception do: [ :ex | 'Exception occurred' dump ]. + '>>>>> BEGINNING OF MAIN' dump. + + [ self main2 ] on: Exception do: [ :ex | 'EXCEPTION CAUGHT IN MAIN....' dump ]. + + '>>>>> END OF MAIN' dump. } } diff --git a/stix/lib/exec.c b/stix/lib/exec.c index a1f3d57..b4bbce4 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -1839,9 +1839,14 @@ static int prim_processor_return_to (stix_t* stix, stix_ooi_t nargs) if (rcv != (stix_oop_t)stix->processor) return 0; /* TODO: check if ctx is a block context or a method context */ + STIX_ASSERT (STIX_CLASSOF(stix, ctx) == stix->_block_context || + STIX_CLASSOF(stix, ctx) == stix->_method_context); ACTIVE_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ - SWITCH_ACTIVE_CONTEXT (stix, ctx); + + + ACTIVE_STACK_PUSH (stix, ret); + SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)ctx); return 1; }