[REBOL] Re: Help me, Obi Reb Kenobi, you're my only hope!
From: tomc:darkwing:uoregon at: 29-Aug-2002 0:31
On Wed, 28 Aug 2002, Ed Dana wrote:
> Yes. But the value that I was trying to assign Fred was the error that
> was to occur when I attempted my action.
you capture that error from 'try
>> either error? err: try[1 / 0 ][true][false]
== true
>> err
** Math Error: Attempt to divide by zero
** Near: 1 / 0
>> either error? err: try[1 / 1][true][false]
== false
>> err
== 1
> More accurately, I have written a couple of daemons, that execute a
> command that I pass to it as a parameter. I wanted the daemon to send
> out an email if it could not execute the action it was assigned.
> Something like this (where Action is the variable that holds the
> statement to be executed:
> If Error? Error: Try [ Do Action] [ Send Warning email ]
> Realizing that Try is similar to Do, I even used:
> If Error? Error: Try [ Action] [ Send Warning email ]
>
been doing something similar daily for years
should not be a problem
> The first executed without issue, making me think that everything was
> executing OK; it wasn't. The second gave me the "no value" error.
>
> But this is why I'm confused: If try is to be used to help trap errors,
> why does it care if a value is set or not? That's why I pointed out that
> I got the error when issuing a "write" command. If anything needed to be
> trapped, it was that. How else can I tell if a file is not there, or I
> don't have access permission, or the file system is too full, etc?
I agree that current behavior does not lead me down the path of least
astonishment.
I would expect err: try[prin ""] to pass quietly
and 'err to have the value it would have after a unset 'err
that is:
>> error? unset 'err
== false
prolly should send it to feedback.
however as a umm.. hack! you could add a constant (anything but an error!)
to the end of your 'try block 'try will return the constant if it gets to
it without encountering an error first.
err: none either error? err: try[ (1 / 0 ) "no-err"][true][false]
== true
>> err
** Math Error: Attempt to divide by zero
** Near: 1 / 0
>> err: none either error? err: try[ (print 1 ) "no-err"][true][false]
1
== false
>> err
== "no-err"
>> err: none either error? err: try[ (1 ) "no-err"][true][false]
== false
>> err
== "no-err"
>> either error? err: try[ make error! "boo" "no-err"][true][false]
== true
>> err
** User Error: boo
** Near: make error! "boo" "no-err"