Newbie getting head around TRY/DISARM
[1/7] from: jkinraid::clear::net::nz at: 15-Nov-2000 12:29
Hello Mat,
> IH> if error? set/any error try [ 0/0 ] [
> IH> error: disarm error
<<quoted lines omitted: 3>>
> works though. (so I'm happy!) This just blows out with the actual error and fails to
> trap it at all.
There are two problems with this piece of code. First, the error that
occurs is a syntax error ('0/0' is an invalid date, '0 / 0' is an
attempt to divide by zero, notice the space). And it appears you can't
trap syntax errors -
>> error? try [0 / 0]
== true
>> error? try [0/0]
** Syntax Error: Invalid date -- 0/0.
** Where: (line 1) error? try [0/0]
The second problem is that the set function takes a word (or block) as
the argument. "set/any error" passes the contents of error to set.
Try this -
if error? set/any 'error try [ 0 / 0 ] [
error: disarm error
print [ "Now you can savely work with: " mold error]
]
Julian Kinraid
[2/7] from: rebol:svendx:dk at: 15-Nov-2000 0:53
Hello Julian,
comments below...
On 15-Nov-00, you wrote:
> Hello Mat,
>> IH> if error? set/any error try [ 0/0 ] [
<<quoted lines omitted: 9>>
> attempt to divide by zero, notice the space). And it appears you can't
> trap syntax errors -
Well, it's tricky at least.
The problem is that the error is triggered before the code is even executed.
compare:
## do "error? try [0/0]"
** Syntax Error: Invalid date -- 0/0.
** Where: (line 1) error? try [0/0]
to:
## error? try [do "0/0"]
== true
>>> error? try [0 / 0]
> == true
>>> error? try [0/0]
> ** Syntax Error: Invalid date -- 0/0.
> ** Where: (line 1) error? try [0/0]
-- snip --
> Julian Kinraid
Best regards
Thomas Jensen
[3/7] from: ingo:2b1 at: 14-Nov-2000 23:29
Hi Mat,
because I was pressed for time, this was the first time I
didn't run my examples through Rebol, and ... well, you see :-(
I made one error, really ... I forgot the ' before error,
but Rebol itself made another, because it doesn't catch the
error ...
if error? set/any 'error try [ 0/0 ] [ ; notice 'error
error: disarm error
print [ "Now you can savely work with: " mold error]
]
the 'error is needed, because otherwise error will be evaluated,
actually, this doesn't work either ...
if error? set/any 'error try [ 0 / 0 ] [ ; notice spaces between 0 / 0
error: disarm error
print [ "Now you can savely work with: " mold error]
]
Now _that_ will work.
(Console session)
>> if error? set/any 'error try [ 0 / 0 ] [
[ error: disarm error
[ print [ "Now you can savely work with: " mold error]
[ ]
Now you can savely work with:
make object! [
code: 400
type: 'math
id: 'zero-divide
arg1: none
arg2: none
arg3: none
near: [0 / 0]
where: none
]
The version 0/0 creates a syntax error, because the parser thinks,
that numbers, seperated by "/" must be a date, and 0/0 is by no means
a valid date. These errors seem not to be handled by 'try ... hmmmm
I hope that clarifies it a bit
Ingo
Once upon a time Mat Bettinson spoketh thus:
> Heya Ingo,
> IH> if error? set/any error try [ 0/0 ] [
<<quoted lines omitted: 11>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
do http://www.2b1.de/
_ . _
ingo@)|_ /| _| _ <We ARE all ONE www._|_o _ _ ._ _
www./_|_) |o(_|(/_ We ARE all FREE> ingo@| |(_|o(_)| (_|
._| ._|
[4/7] from: mat:eurogamer at: 14-Nov-2000 12:56
Hello folks,
I'm new to the list. I've been tinkering with Rebol making some damn
handy scripts. Never done anything this productive since the Amiga!
Anyhow, I've got a damn nice script that automatically uploads me some
game server log files. Unfortunately I'm having trouble trapping
errors. The examples given in the official guide basically seem broken
to me.
For example;
if error? bleet: try [ delete xUploadFile ] [
print ["* File locked, skipping..." filen]
probe disarm bleet
return false
][
Quite straight forward you would have thought. Ripped straight from an
example in the official guide. Well, it just doesn't WORK. It blows
out claiming that bleet: must have some value. So does bleet get no
value if there is no error in the try block?
Then why does the official guide have this example;
>> if error? error: try [ 1/0 ] [ [probe disarm error ]
Is this not exactly the same as my form?
Previously I had something simply in the format of;
if error? try [ delete file ] [ Whine a bit ]
But suddenly I was getting zillions of errors when there were no
errors (specifically ftp uploading). So I assume I need to disarm it
but now I can't get this form to work at all.
--
Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee
http://www.eurogamer.net | http://www.eurogamer-network.com
[5/7] from: ingo:2b1 at: 14-Nov-2000 14:14
Hi Mat,
try returns whatever the block returns, e.g.
try [ 1+1 ] ;returns 2
try [ 0/0 ] ;returns an error, but
try [ print "this" ] ;returns nothing, because 'print doesn't
; return a value
two possible solutions:
error: try [ print "this" true ] ; be sure a value is returned,
; when no error
set/any error try [ print "this" ] ; to set error to whatever
; value, even if it happens
; to be nothing
about disarming:
set/any error try [ 0/0 ]
error now contains an error value, and if you try to use error
somewhere else, e.g.
print error
the error is raised, the only way to use the error value is to
disarm it
print mold disarm error
or error: disarm error
if error? set/any error try [ 0/0 ] [
error: disarm error
print [ "Now you can savely work with: " mold error]
]
I hope that helps,
Ingo
Once upon a time Mat Bettinson spoketh thus:
> Hello folks,
> I'm new to the list. I've been tinkering with Rebol making some damn
<<quoted lines omitted: 28>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
do http://www.2b1.de/
_ . _
ingo@)|_ /| _| _ <We ARE all ONE www._|_o _ _ ._ _
www./_|_) |o(_|(/_ We ARE all FREE> ingo@| |(_|o(_)| (_|
._| ._|
[6/7] from: mat:eurogamer at: 14-Nov-2000 14:37
Heya Ingo,
[Education on the ways of error disarming]
IH> I hope that helps,
Oh yes, you're an scholar and a gentleman!
--
Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee
http://www.eurogamer.net | http://www.eurogamer-network.com
[7/7] from: mat:eurogamer at: 14-Nov-2000 14:44
Heya Ingo,
IH> if error? set/any error try [ 0/0 ] [
IH> error: disarm error
IH> print [ "Now you can savely work with: " mold error]
IH> ]
This doesn't actually work though? Using true to force error to return
works though. (so I'm happy!) This just blows out with the actual error and fails to
trap it at all.
--
Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee
http://www.eurogamer.net | http://www.eurogamer-network.com
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted