Catching Script Error
[1/7] from: chris::starforge::co::uk at: 16-Jul-2001 21:07
Hi,
I've managed to run into another problem :)
>> testing: {foo ["bar" "quux" "ping"]}
>> do testing
** Script Error: foo has no value
Well, I expected that, but I want to be able to recover from that sort of
problem. Ok, try try..
>> try [do testing]
** Script Error: foo has no value
Hmm.. not good.
>> if error? result: try [do testing] [
[ disarm result
[ print "Oops"
]
Oops
Getting there....
>> if error? result: try [do testing] [
[ disarm result
[ print result/id
]
** Script Error: foo has no value
Rats!
In other words - is there some way I can recover gracefully from an error in
a script and give some useful feedback on where the problem was without
REBOL going into a sulk? I can get by with the "There was an error in the
command body", but I'd prefer to be able to give a more useful message :/
Chris
--
New sig in the works
Explorer2260, Designer and Coder
http://www.starforge.co.uk
--
You can't carve your way to success without cutting remarks.
[2/7] from: tim:johnsons-web at: 16-Jul-2001 13:40
Hi Chris:
> In other words - is there some way I can recover gracefully from an error in
> a script and give some useful feedback on where the problem was without
> REBOL going into a sulk? I can get by with the "There was an error in the
> command body", but I'd prefer to be able to give a more useful message :/
Below are dispatch blocks from one of my projects:
Have a look at the recovery block and see if that works for
you. The sum result is that the rebol error is captured there and the
application can procede to some sort of a professional conclusion
if error? set/any 'err
try[
imports
run cgio
if okay [
blk: cgio/read-write-file/break-at Template "<!--BEGIN-->"
run-command
cgio/read-write-file/resume none blk
]
close-cgi cgio
][; recovery block
err: disarm err
prin rejoin ["<br>" newline "======>ERROR: "]
print reform bind (get in (get in system/error err/type) err/id) in err 'type
close-cgi cgio
]
HTH
tj
p.s. below is simple error routine
toss: func[arg][make error! rejoin arg]
[3/7] from: rotenca:telvia:it at: 17-Jul-2001 2:49
> In other words - is there some way I can recover gracefully from an error in
> a script and give some useful feedback on where the problem was without
> REBOL going into a sulk? I can get by with the "There was an error in the
> command body", but I'd prefer to be able to give a more useful message :/
Try this:
if error? result: try [do testing] [
result: disarm result
probe get in get in system 'error result/type result/id
]
> Chris
romano
[4/7] from: chris:starforge:demon at: 17-Jul-2001 14:16
Romano Paolo Tenca wrote:
<snip>
Thanks, I'll give this a try..
> probe get in get in system 'error result/type result/id
How on earth did you work that out? :)
Chris
--
New sig in the works
Explorer2260 Designer and Coder
http://www.starforge.co.uk
[5/7] from: rotenca:telvia:it at: 17-Jul-2001 19:42
The answer of Tim Johnson was better than mine, here it is:
print reform bind (get in (get in system/error err/type) err/id) in err
'type
so he gives "magically" to "arg" word(s) in system/error/(type)/(id) the
meaning they have in the object err
> > probe get in get in system 'error result/type result/id
>
> How on earth did you work that out? :)
looking at system/error ;-)
> Chris
romano
[6/7] from: tim:johnsons-web at: 17-Jul-2001 11:27
On Tue, Jul 17, 2001 at 07:42:06PM +0200, Romano Paolo Tenca wrote:
> The answer of Tim Johnson was better than mine, here it is:
Hi All:
And to give credit where credit is due. I got that solution from
this list.
Love this list!!
tj
> print reform bind (get in (get in system/error err/type) err/id) in err
> 'type
<<quoted lines omitted: 10>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.johnsons-web.com
[7/7] from: chris:starforge at: 17-Jul-2001 20:01
On 17-Jul-01, Romano Paolo Tenca wrote:
> The answer of Tim Johnson was better than mine, here it is:
> print reform bind (get in (get in system/error err/type) err/id) in
> err 'type
Many thanks to you and Tim for the help, it's now working fine :))
Chris
--
New sig in the works
Explorer2260, Designer and Coder
http://www.starforge.co.uk
--
Matrimony isn't a word, it's a sentence.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted