reset the sender field to stix->_nil when creating a new process over a block context .
touched up exception handling implementation code
This commit is contained in:
@ -241,12 +241,12 @@
|
||||
<exception>
|
||||
handlerActive := true.
|
||||
|
||||
thisContext isHandlerContext dump.
|
||||
"thisContext isHandlerContext dump.
|
||||
(thisContext basicSize) 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: ABOUT TO EVALUE THE RECEIVER BLOCK' dump.
|
||||
'on:do: ABOUT TO EVALUE THE RECEIVER BLOCK' dump."
|
||||
|
||||
^self value.
|
||||
}
|
||||
@ -288,6 +288,11 @@ thisContext isHandlerContext dump.
|
||||
self new signal: text
|
||||
}
|
||||
|
||||
#method messageText
|
||||
{
|
||||
^self.messageText
|
||||
}
|
||||
|
||||
#method signal
|
||||
{
|
||||
self.signalContext := thisContext.
|
||||
@ -299,10 +304,6 @@ thisContext isHandlerContext dump.
|
||||
self.handlerContext isNil
|
||||
ifTrue: [ self notHandled ]
|
||||
ifFalse: [ self handle ].
|
||||
|
||||
## self isHandled
|
||||
## ifTrue: [ self handle ]
|
||||
## ifFalse: [ self notHandled ].
|
||||
}
|
||||
|
||||
#method signal: text
|
||||
@ -314,7 +315,8 @@ thisContext isHandlerContext dump.
|
||||
#method pass
|
||||
{
|
||||
## pass the exception to the outer context
|
||||
## TODO:
|
||||
|
||||
## TODO: Should i change the signalContex to thisContext???
|
||||
self.handlerContext := self findHandlerContextStartingFrom: (self.handlerContext sender).
|
||||
self.handlerContext isNil
|
||||
ifTrue: [ self notHandled ]
|
||||
@ -330,23 +332,23 @@ thisContext isHandlerContext dump.
|
||||
|
||||
#method retry
|
||||
{
|
||||
## ##>>> Processor return: nil to: (self.signalContext sender).
|
||||
## TODO: verify if return:to: causes unnecessary stack growth.
|
||||
|
||||
self.handlerContext pc: 0.
|
||||
Processor return: self to: self.handlerContext.
|
||||
##Processor forceContext: self.handlerContext.
|
||||
}
|
||||
|
||||
#method resume
|
||||
{
|
||||
## TODO: verify if return:to: causes unnecessary stack growth.
|
||||
## is this correct???
|
||||
Processor return: nil to: (self.signalContext sender).
|
||||
Processor return: self to: (self.signalContext sender).
|
||||
}
|
||||
|
||||
## ####################################################################
|
||||
## ####################################################################
|
||||
|
||||
#method isHandled
|
||||
{
|
||||
^self handlerContext notNil
|
||||
}
|
||||
|
||||
#method handle
|
||||
{
|
||||
Processor return: (self.handlerContext handlerBlock value: self) to: (self.handlerContext sender)
|
||||
@ -383,4 +385,8 @@ Processor activeProcess terminate.
|
||||
|
||||
#class NoSuchMessageException(Exception)
|
||||
{
|
||||
#method signal
|
||||
{
|
||||
self signal: 'no such message'.
|
||||
}
|
||||
}
|
||||
|
@ -386,4 +386,11 @@
|
||||
<primitive: #_processor_return_to>
|
||||
self primitiveFailed.
|
||||
}
|
||||
|
||||
#method forceContext: aContext
|
||||
{
|
||||
<primitive: #_processor_force_context>
|
||||
self primitiveFailed.
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,13 +40,18 @@
|
||||
#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. ex return: 9999. 'AFTER RETURN' dump. ].
|
||||
k := ['this is test-011' dump. Exception signal: 'main2 screwed...'. 8888 dump. ]
|
||||
on: Exception do: [ :ex | 'Exception occurred' dump. ex messageText dump. 'Getting back to....' dump. "ex return: 9999." ex pass. 'AFTER RETURN' dump. ].
|
||||
|
||||
k dump.
|
||||
'END OF test-011' dump.
|
||||
}
|
||||
|
||||
#method(#class) raise_exception
|
||||
{
|
||||
Exception signal: 'bad exceptinon'.
|
||||
}
|
||||
|
||||
#method(#class) test3
|
||||
{
|
||||
| k j |
|
||||
@ -54,23 +59,115 @@
|
||||
k := [
|
||||
'>>> TEST3 METHOD >>> ' dump.
|
||||
j dump.
|
||||
(j < 25) ifTrue: [Exception signal].
|
||||
(j < 25) ifTrue: [ | t |
|
||||
t := Exception signal: 'bad exceptinon'. ## when resume, t should get Exception.
|
||||
t := self raise_exception. ## when resumed, t should get 'self'
|
||||
'RESUMED???' dump.
|
||||
t dump.
|
||||
j dump.
|
||||
].
|
||||
|
||||
'OOOOOOOOOOOOOOOOOOOOOOO' dump.
|
||||
'JJJJJJJJJJJJJJ' dump.
|
||||
] on: Exception do: [ :ex | 'Exception occurred' dump. j := j + 1. ex resume. ].
|
||||
] on: Exception do: [ :ex | 'Exception occurred' dump. ex messageText dump. j := j + 1. ex resume. ].
|
||||
|
||||
k dump.
|
||||
'END OF test-011' dump.
|
||||
'END OF TEST3' dump.
|
||||
}
|
||||
|
||||
#method(#class) test4_1
|
||||
{
|
||||
| k j |
|
||||
j := 20.
|
||||
k := [
|
||||
'>>> TEST4_1 METHOD >>> ' dump.
|
||||
j dump.
|
||||
(j < 25) ifTrue: [ | t |
|
||||
##t := Exception signal: 'bad exceptinon'. ## when resume, t should get Exception.
|
||||
t := self raise_exception. ## when resumed, t should get 'self'
|
||||
'RESUMED???' dump.
|
||||
t dump.
|
||||
j dump.
|
||||
].
|
||||
|
||||
'OOOOOOOOOOOOOOOOOOOOOOO' dump.
|
||||
'JJJJJJJJJJJJJJ' dump.
|
||||
] on: Exception do: [ :ex | 'Exception occurred' dump. ex messageText dump. j := j + 1. ex pass. ].
|
||||
|
||||
k dump.
|
||||
'END OF TEST4_1' dump.
|
||||
}
|
||||
|
||||
#method(#class) test4
|
||||
{
|
||||
'BEGINNING OF TEST4' dump.
|
||||
[ self test4_1 ] on: Exception do: [:ex | 'Excepton in test4_1' dump. ex messageText dump. ex resume].
|
||||
'END OF TEST4' dump.
|
||||
}
|
||||
|
||||
|
||||
#method(#class) test5
|
||||
{
|
||||
| k j |
|
||||
'BEGINNING OF TEST5' dump.
|
||||
j := 20.
|
||||
k := [
|
||||
'>>> TEST5 BLOCK >>> ' dump.
|
||||
j dump.
|
||||
(j < 25) ifTrue: [ | t |
|
||||
##t := Exception signal: 'bad exceptinon'. ## when resume, t should get Exception.
|
||||
t := self raise_exception. ## when resumed, t should get 'self'
|
||||
].
|
||||
|
||||
'OOOOOOOOOOOOOOOOOOOOOOO' dump.
|
||||
'JJJJJJJJJJJJJJ' dump.
|
||||
] on: Exception do: [ :ex | 'Exception occurred' dump. ex messageText dump. j := j + 1. ex retry. ].
|
||||
|
||||
k dump.
|
||||
'END OF TEST5' dump.
|
||||
}
|
||||
|
||||
#method(#class) test11
|
||||
{
|
||||
## exception is raised in a new process. it can't be captured
|
||||
## by an exception handler of a calling process.
|
||||
## exception handling must not cross the process boundary.
|
||||
[
|
||||
|p |
|
||||
p := [Exception signal: 'Sample Exception' ] newProcess.
|
||||
'JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ' dump.
|
||||
p resume.
|
||||
] on: Exception do: [:ex | 'EXCEPTION ----------' dump. ex messageText dump ].
|
||||
}
|
||||
|
||||
#method(#class) test12
|
||||
{
|
||||
[
|
||||
|p |
|
||||
p := [
|
||||
[ Exception signal: 'Sample Exception' ] on: Exception do: [:ex | 'EXCEPTION CAUGHT...' dump. ex messageText dump. ]
|
||||
] newProcess.
|
||||
'JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ' dump.
|
||||
p resume.
|
||||
] on: Exception do: [:ex | 'EXCEPTION ----------' dump. ex messageText dump ].
|
||||
}
|
||||
|
||||
#method(#class) main
|
||||
{
|
||||
|
||||
'>>>>> BEGINNING OF MAIN' dump.
|
||||
|
||||
[ self main2 ] on: Exception do: [ :ex | 'EXCEPTION CAUGHT IN MAIN....' dump. "ex pass" ].
|
||||
## [ self main2 ] on: Exception do: [ :ex | 'EXCEPTION CAUGHT IN MAIN....' dump. ex messageText dump. "ex pass." ex resume. ].
|
||||
|
||||
'##############################' dump.
|
||||
self test3.
|
||||
## self test3.
|
||||
## self test4.
|
||||
|
||||
self test5.
|
||||
## self test11.
|
||||
## self test12.
|
||||
|
||||
##100 timesRepeat: ['>>>>> END OF MAIN' dump].
|
||||
'>>>>> END OF MAIN' dump.
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user