Hi Joel,
Those were the words of [EMAIL PROTECTED]:
<...>
> REBOL [ Author: "Joel Neely" ]
>
> gotpage?: func [ pagename /local result ][
> result: try [read pagename]
> either error? result
> [ print "Bletch!" return false ]
> [ print "Hooray!" return true ]
> ]
>
> with the following results (lines wrapped to fit email)
>
> >> gotpage? http://www.fedex.com/
> Hooray!
> == true
> >> gotpage? http://nohost.org/nopage.html
> ** User Error: Error. Target url: http://nohost.org/nopage.html
> could not be retrieved.
> Server response: HTTP/1.0 503 Service Unavailable.
> ** Where: read pagename
> >>
>
> Can error values not be stored in a variable? How can I retain the
> error message for future reference without my entire script crashing?
As I understand it, when you do
either error? result
result is evaluated, and thus the error is raised.
You need to disarm the error object first, e.g.
gotpage?: func [ pagename /local result ][
either error? result: try [read pagename] [
print mold disarm result
return false
] [
print "Hooray!"
return true
]
]
Be careful to always return a value from the try
block, otherwise you'll get a script error, that
result hasn't got a value, see:
>> if error? err: try [ print xyz ] [ print "error" ]
error
>> if error? err: try [ print 1 ] [ print "error" ]
1
** Script Error: err needs a value.
** Where: if error? err: try [print 1]
>> if error? err: try [ print 1 true ] [ print "error" ]
1
== false
>>
regards,
Ingo
-- _ . _
ingo@)|_ /| _| _ <We ARE all ONE www._|_o _ _ ._ _
www./_|_) |o(_|(/_ We ARE all FREE> ingo@| |(_|o(_)| (_|
http://www.2b1.de/Rebol/ ._| ._|