global error handling?
[1/7] from: maximo::meteorstudios::com at: 24-Jul-2003 19:33
hi,
me again (seems I'm asking more than helping these days ;-)
is there a way to handle an error globaly by putting a "hook" or appending to a block
somewhere deep in the system funcs.
I ask because I'm wondering if its possible to catch when an unset word is evaluated...
I'd run some code just before an actual "unset value" error is generated... it would
also be usefull to be able to execute code just after the error, do some magic and return
to the application right after (I'll let you figure out what the unset value hook would
do ;-)
This has many uses and if its possible I'd like to integrate the mechanism in steel...
thanks in advance!
-max
-----------
meteor Studios, T.D.
-----------
Never Argue with an idiot. They will bring you down to their level and beat you with
experience
[2/7] from: andrew:martin:colenso:school at: 25-Jul-2003 13:09
Max wrote:
> me again (seems I'm asking more than helping these days ;-)
Hey, there's a give and take in most people's lives.
> I ask because I'm wondering if its possible to catch when an unset
word is evaluated...
Would it still work if silly people like myself did this:
>> type? do [print "123"]
123
== unset!
:)
> is there a way to handle an error globaly by putting a "hook" or
appending to a block somewhere deep in the system funcs.
I don't know if this is helpful or not but the 'throw and 'catch words
might be useful? Perhaps 'try, 'attempt, and 'error! might be useful?
Andrew J Martin
Attendance Officer &
Information Systems Trouble Shooter
Colenso High School
Arnold Street, Napier.
Tel: 64-6-8310180 ext 826
Fax: 64-6-8336759
http://colenso.net/scripts/Wiki.r?AJM
http://www.colenso.school.nz/
[3/7] from: g:santilli:tiscalinet:it at: 25-Jul-2003 10:02
Hi Maxim,
On Friday, July 25, 2003, 1:33:42 AM, you wrote:
MOA> This has many uses and if its possible I'd like to integrate the mechanism in steel...
I think you can't do what you're thinking of. (You'd need
continuations, or some way to come back to the point where an
exception was raised after it was raised.)
If you want to make steel load libraries automatically based on
the words a script it using, you could do it in a different way
though. As long as all of the script is loaded, you have all of
its words in SYSTEM/WORDS. If you QUERY/CLEAR SYSTEM/WORDS
*before* loading the script and then QUERY it again after loading
it you'll see all the new words present in the script; you can
look for them and collect those that are unset.
>> query/clear system/words
== [end! unset! error! datatype! context! native! action! routine! op! function! object!
struct! library! p
ort! any-type! any-word!...
>> s: load {print "hello" some-library-func print "finished"}
== [print "hello" some-library-func print "finished"
]
>> query system/words
== [s some-library-func]
>> value? 'some-library-func
== false
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[4/7] from: maximo:meteorstudios at: 25-Jul-2003 8:17
From: Andrew Martin [mailto:[andrew--martin--colenso--school--nz]]
> > I ask because I'm wondering if its possible to catch when an unset
> word is evaluated...
>
> Would it still work if silly people like myself did this:
>
> >> type? do [print "123"]
> 123
> == unset!
well that's the worst case scenario, because print does not return a value, but it does
exist by itself.
But, in your code, there was no error generated, because you wanted to retrieve the type?
which actually IS unset...
I'd mainly like do something like:
;-----------------------------------------------------------------------------------
rebol []
catch-error-hook: error-handler ['unset-word error-data /local word] [
word: error-data/word
set word select load %optional-funcs.r error-word
either word [
return ; return to code, just before evaluation the word
][
throw 'unset-word ; really generate the error...
]
]
value: myfunc
ask "done..."
;-------------------------------------------------------------------------------------
Here, the hook would set the myfunc word (globaly) just before it actually was going
to be evaluated (if the rebol parser didn't find a value for it yet).
> > is there a way to handle an error globaly by putting a "hook" or
> appending to a block somewhere deep in the system funcs.
>
> I don't know if this is helpful or not but the 'throw and 'catch words
> might be useful? Perhaps 'try, 'attempt, and 'error! might be useful?
>
they are functions, they don't map to the global context, AFAIK they interrupt the error
before the error occurs, but divert execution to a new block.
Its like saying : I can't find door to room A ... well then, go to room B instead.
What I want is to try and find the room A somewhere else (by getting a floorplan!).
Another example is getting to call rugby-type server anytime an unset-word is evaluated...
-Max
[5/7] from: maximo:meteorstudios at: 25-Jul-2003 9:44
I think you've given me an idea.
since the user.r script is executed BEFORE the actual script file is loaded, I am able
to see what new words have been loaded.
all I then need to do is see if rebol itself uses do and or do load
if this is so, I might prepare a little patched version of do. if this all works out,
it would attempt to fill-in the value of any unset words right after loading the code
:-)
invisible and then your own do statements would benefit of this invisible library loading.
NB: Some might have apprehension towards this system, but I program in maya's mel and
it has a hook which loads code as it needs it and its really nice... cause you can extend
the language via libraries of code without having to do know if its been linked to or
not... since its loaded at run time, not all of the zillion functions are loaded, reducing
memory comsumption.
-max
-----------
meteor Studios, T.D.
-----------
Never Argue with an idiot. They will bring you down to their level and beat you with
experience
[6/7] from: g:santilli:tiscalinet:it at: 25-Jul-2003 16:08
Hi Maxim,
On Friday, July 25, 2003, 3:44:41 PM, you wrote:
MOA> if this is so, I might prepare a little patched version of
MOA> do. if this all works out, it would attempt to fill-in the
MOA> value of any unset words right after loading the code :-)
Instead of patching DO, you could just do a QUERY/CLEAR in user.r
and the write a function, say AUTO-LIB-LOADER, that you just have
to call at the beginning of your script.
Indeed, it could be a nice idea...
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[7/7] from: greggirwin:mindspring at: 25-Jul-2003 10:29
Hi Max,
MOA> is there a way to handle an error globaly by putting a "hook" or
MOA> appending to a block somewhere deep in the system funcs.
Below is something Brett cooked up, which might give you some ideas.
-- Gregg
REBOL [
Author: "Brett Handley"
Date: 22-Jan-2003
Comment: "To simulate Gregg's idea of an insert-error-func system."
]
system/error: make system/error [
error-funcs: copy []
detect: func [ [catch] error [error!]] [
foreach evt-func error-funcs [
if not error? evt-func: evt-func error [
return either evt-func [error] [none]
]
]
error
]
]
insert-error-func: func [
{Add a function to monitor global errors. Return the func.}
funct [block! function!] "A function or a function body block"
] [
if block? :funct [funct: func [error [error!]] funct]
insert system/error/error-funcs :funct
:funct
]
remove-error-func: func [
"Remove an error function previously added."
funct [function!]
] [
remove any [find system/error/error-funcs :funct ""]
]
app-wait: has [result] [
forever [
if not error? set/any 'result try [wait []] [break]
system/error/detect result
]
]
; ---- Example Application
insert-error-func [
error: disarm error
if block? msg: get in get in system/error error/type error/id [
msg: bind/copy msg in error 'self
]
alert reform msg
false
]
view/new layout [
button "Divide by zero" [1 / 0]
button "Read %/h/test" [read %/h/test]
]
app-wait