added more code for exception handling

This commit is contained in:
hyunghwan.chung 2016-05-01 13:49:36 +00:00
parent 8ea80dae91
commit 90eb7d5507
3 changed files with 62 additions and 11 deletions

View File

@ -246,7 +246,7 @@ thisContext isHandlerContext dump.
(thisContext basicAt: 8) dump. ## this should be anException
(thisContext basicAt: 9) dump. ## this should be anExceptionBlock
(thisContext basicAt: 10) dump. ## this should be handlerActive
'on:do: ok.............' dump.
'on:do: ABOUT TO EVALUE THE RECEIVER BLOCK' dump.
^self value.
}
@ -291,9 +291,18 @@ thisContext isHandlerContext dump.
#method signal
{
self.signalContext := thisContext.
self isHandled
ifTrue: [ self handle ]
ifFalse: [ self notHandled ].
self.handlerContext isNil ifTrue: [
self.handlerContext := self findHandlerContextStartingFrom: self.signalContext
].
self.handlerContext isNil
ifTrue: [ self notHandled ]
ifFalse: [ self handle ].
## self isHandled
## ifTrue: [ self handle ]
## ifFalse: [ self notHandled ].
}
#method signal: text
@ -306,8 +315,33 @@ thisContext isHandlerContext dump.
{
## pass the exception to the outer context
## TODO:
self.handlerContext := self findHandlerContextStartingFrom: (self.handlerContext sender).
self.handlerContext isNil
ifTrue: [ self notHandled ]
ifFalse: [ self handle ].
}
#method return: value
{
self.handlerContext isNil ifFalse: [
Processor return: value to: (self.handlerContext sender)
]
}
#method retry
{
## ##>>> Processor return: nil to: (self.signalContext sender).
}
#method resume
{
## is this correct???
Processor return: nil to: (self.signalContext sender).
}
## ####################################################################
## ####################################################################
#method isHandled
{
^self handlerContext notNil

View File

@ -41,7 +41,23 @@
{
| 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 ].
on: Exception do: [ :ex | 'Exception occurred' dump. ex dump. 'Getting back to' dump. ex return: 9999. 'AFTER RETURN' dump. ].
k dump.
'END OF test-011' dump.
}
#method(#class) test3
{
| k j |
j := 20.
k := [
'>>> TEST3 METHOD >>> ' dump.
j dump.
(j < 25) ifTrue: [Exception signal].
'OOOOOOOOOOOOOOOOOOOOOOO' dump.
'JJJJJJJJJJJJJJ' dump.
] on: Exception do: [ :ex | 'Exception occurred' dump. j := j + 1. ex resume. ].
k dump.
'END OF test-011' dump.
@ -50,9 +66,11 @@
#method(#class) main
{
'>>>>> BEGINNING OF MAIN' dump.
[ self main2 ] on: Exception do: [ :ex | 'EXCEPTION CAUGHT IN MAIN....' dump ].
[ self main2 ] on: Exception do: [ :ex | 'EXCEPTION CAUGHT IN MAIN....' dump. "ex pass" ].
'##############################' dump.
self test3.
'>>>>> END OF MAIN' dump.
}
}

View File

@ -1854,13 +1854,12 @@ static int prim_processor_return_to (stix_t* stix, stix_ooi_t nargs)
ctx = ACTIVE_STACK_GET(stix, stix->sp);
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);
if (STIX_CLASSOF(stix, ctx) != stix->_block_context &&
STIX_CLASSOF(stix, ctx) == stix->_method_context) return 0;
ACTIVE_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */
ACTIVE_STACK_PUSH (stix, ret);
SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)ctx);