[REBOL] Re: Newbie getting head around TRY/DISARM
From: ingo:2b1 at: 14-Nov-2000 14:14
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
set/any error try [ 0/0 ]
error now contains an error value, and if you try to use error
somewhere else, e.g.
the error is raised, the only way to use the error value is to
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,
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
> 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
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
_ . _
ingo@)|_ /| _| _ <We ARE all ONE www._|_o _ _ ._ _
www./_|_) |o(_|(/_ We ARE all FREE> ingo@| |(_|o(_)| (_|