Lutz,
(MAIN)-> (net-connect "localhost" 23)
nil
(MAIN)-> (net-error)
(4 "ERR: Connection failed")
(MAIN)-> (sys-error)
(111 "Connection refused")
The example shows (111 "Connection refused"),does this mean that
all errors from the "net-..." functions are always covert by (sys-error?)
last but not least.. Im unable to get the (error-event) to work on
linux... Is it correct that when having an event-handler running it will
automaticly throw the error and execute its function? Or should I explicitly
call for the return value? (i didnt think so though...) Anyway the example
from the manual doesnt work here..
The output of 'sys-error' is very platform dependent a number/message on one Unix can be very different on another flavor of UNIX.
Not all errors reported by 'net-error' have an underlying 'sys-error' giving more detail to 'net-error'.
'error-number' and 'error-text' only cover newLISP's own error system and not number and messages generated by 'sys-error'.
To make a long story short: we need both. The normal 'net-error' and other error mesages are platform independent. 'sys-error' gives you more info mainly about error conditions having to do with your system's I/O. So you could use 'sys-error' also on failing calls to 'open', 'read', 'write' and related newLISP function calls.
'error-event' works fine for me on UBUNTU Linux and I have never seen it fail on any other OS (Win32, MacOSX, freeBSD, Solaris). If you have a bug in your error handler then the system would hang, because the error handler would call itself. Note that one of the manual examples calls an undefined routine (restart-program), take that out. Once you have executed (error-event the-handler) it will automatically call the function defined in 'the-handler' on error conditions unless you use 'catch' to catch it.
yes ..ok.. I just wanted to make sure I understound it ;-)
but regarding (error-event)..
Oke here the example:
(define (my-handler) (println "MY-ERR:" (last (net-error)) ))
(error-event 'my-handler)
(net-connect "localhost" 23)
The above doesnt return anything!
It only works when i use (throw (net-connect 'localhost" 23))
Is that correct? because the manual implicates a general error-catcher
using error-event without using throw to get it working..
This is correct behavior because 'net-connect' (and many other I/O) routines return 'nil' on error and set 'net-error' but will not throw and error.
This has been done to make code possible like this:
(if (set 'connection (net-connect host port))
(net-send connection stuff-to-send)
(do-error-stuff))
This is much shorter/convenient then handling I/O errors using 'catch'. In the internet domain you could see connection errors as something "normal", not necessary a programming error. Of course when you use 'throw' to throw a user error then your error handler will catch it, as your example code is doing it.
On the other side if you specify wrong parameter types, e.g. a number instead of a domain in host then an error gets thrown, signaling a programming error.
Thanks Lutz.. Though I think I just might be using the wrong test cases ;-)
i.e.
With the error-handler above this is not returning either..
(replacing (net-error) with (sys-error) )
(append-file "/root/blabla" "itsme")
where i would expect (13 "Permission denied")..
Im a little confused right now ;-)
in your example use 'throw-error' instead of 'throw'.