[REBOL] Re: Newbie getting head around TRY/DISARM
From: jkinraid::clear::net::nz at: 15-Nov-2000 12:29
> 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.
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]
>> 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]