[REBOL] Re: Help me, Obi Reb Kenobi, you're my only hope!
From: lmecir:mbox:vol:cz at: 2-Sep-2002 15:11
Hi Romano,
<<Romano>>
...
I also was experimenting with do/next and this is my code. It try to handle
also return, throw, break.
isr?: function [blk [block!]][res][
while [not tail? blk][
either error? try [
error? catch [
error? do does [
error? loop 1 [
error? set 'res do/next compose [error? (blk)]
]
]
]
][
return true
][
if none? res [prin "control detected " return false]
blk: second res
res: none
]
]
false
]
block2: head insert tail copy [] try [first []]
isr? [1 2 first block2 3] ;==false
isr? [1 2 first block 3] ;==true
isr? [1 2 throw first block2 3] ;==control detected false
isr? [1 2 throw first block 3] ;==true
isr? [1 2 return first block2 3] ;==control detected false
isr? [1 2 return first block 3] ;==true
isr? [1 2 break/return first block2 3] ;==control detected false
isr? [1 2 break/return first block 3] ;==true
<</Romano>>
1a) THROW. My DEFAULT2 function "works" as follows:
default2/good [1 2 throw first block2 3] ["caught"] ["passed"]
** Throw Error: ** Script Error: Out of range or past end
** Near: first []
i.e. it isn't able to catch this kind of error. The ISR? function seems to
not notice there was an error.
1b) However:
type? catch [default2/good [1 2 throw first block2 3] ["caught"]
["passed"]] ; == error!
, i.e. DEFAULT2 works as expected in this case.
type? catch [isr? [1 2 throw first block2 3]] ; control detected ==
logic!
, i.e. the ISR? function "creates" an artifact.
For RETURN and BREAK I obtained equivalent results.
I would prefer to have the ability to catch even BREAK, RETURN and THROW
errors, which I cannot do now (AFAIK!).
Ciao
Ladislav