started correcting ensure: implementation
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
|
||||
#class(#pointer) Context(Apex)
|
||||
{
|
||||
#dcl sender ip sp ntmprs.
|
||||
#dcl sender ip sp ntmprs ensure_block.
|
||||
|
||||
#method sender
|
||||
{
|
||||
@ -75,6 +75,8 @@
|
||||
|
||||
#method findExceptionHandlerBlock: anExceptionClass
|
||||
{
|
||||
## find an exception handler block for a given exception class.
|
||||
##
|
||||
## for this to work, self must be an exception handler context.
|
||||
## For a single on:do: call,
|
||||
## self class specNumInstVars must return 8.
|
||||
@ -85,7 +87,9 @@
|
||||
| bound exc |
|
||||
## NOTE: if on:do: has a temporary varible, bound must be adjusted to reflect it.
|
||||
bound := self basicSize - 1.
|
||||
8 to: bound by: 2 do: [ :i |
|
||||
## TODO: change 9 to a constant when stix is enhanced to support constant definition
|
||||
## or calcuate the minimum size using the class information.
|
||||
9 to: bound by: 2 do: [ :i |
|
||||
exc := self basicAt: i.
|
||||
((anExceptionClass == exc) or: [anExceptionClass inheritsFrom: exc]) ifTrue: [^self basicAt: (i + 1)].
|
||||
]
|
||||
@ -330,6 +334,7 @@ thisContext isExceptionHandlerContext dump.
|
||||
{
|
||||
## TODO: ensure that the ensured block is executed after exception handler...
|
||||
| v |
|
||||
self.ensure_block := aBlock.
|
||||
v := self on: Exception do: [:ex |
|
||||
aBlock value.
|
||||
ex pass
|
||||
|
@ -111,7 +111,25 @@
|
||||
"
|
||||
|
||||
}
|
||||
|
||||
|
||||
#method(#class) aaa_123
|
||||
{
|
||||
| v1 |
|
||||
v1 := [
|
||||
| k |
|
||||
k := 99.
|
||||
[
|
||||
[
|
||||
##[ Exception signal: 'simulated error' ] ensure: [('ensure 1 ', (k asString)) dump ].
|
||||
[ ^20 ] ensure: [('ensure 1 ', (k asString)) dump ].
|
||||
] ensure: ['ensure 2' dump ].
|
||||
] ensure: ['ensure 3' dump ].
|
||||
] on: Exception do: [:ex |
|
||||
('EXCETION - ' , ex messageText) dump.
|
||||
## Exception signal: 'qqq'.
|
||||
].
|
||||
^v1
|
||||
}
|
||||
#method(#class) main
|
||||
{
|
||||
| v1 |
|
||||
@ -131,17 +149,21 @@
|
||||
|
||||
"[1 xxx] ifCurtailed: ['XXXXXXXX CURTAILED XXXXXXXXX' dump. Exception signal: 'jjjj']."
|
||||
|
||||
v1 := [
|
||||
" v1 := [
|
||||
| k |
|
||||
k := 99.
|
||||
[
|
||||
[ Exception signal: 'simulated error' ] ensure: [('ensure 1 ', (k asString)) dump ].
|
||||
] ensure: ['ensure 2' dump ].
|
||||
[
|
||||
##[ Exception signal: 'simulated error' ] ensure: [('ensure 1 ', (k asString)) dump ].
|
||||
[ ^20 ] ensure: [('ensure 1 ', (k asString)) dump ].
|
||||
] ensure: ['ensure 2' dump ].
|
||||
] ensure: ['ensure 3' dump ].
|
||||
] on: Exception do: [:ex |
|
||||
('EXCETION - ' , ex messageText) dump.
|
||||
## Exception signal: 'qqq'.
|
||||
].
|
||||
|
||||
"
|
||||
v1 := self aaa_123.
|
||||
'--------------------------------' dump.
|
||||
v1 dump.
|
||||
'END OF MAIN' dump.
|
||||
|
Reference in New Issue
Block a user