Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Trapping errors? - Not like the book says?

 [1/5] from: doug::vos::eds::com at: 3-Aug-2000 10:06


I have read and re-read the sections REBOL the official guide. about errors. (eg. pages 276 and following) Then I put together a function to log errors called log-event (with a refinement for handling disarmed error objects). The log-event function will then log the date, time, script name, "error", and molded error object. if error? error: try [send [joe--blow--go--go] {test} ][ ; this will probably force an error log-event/error system/script/header/file "error" (disarm error) ; since go.go is not a valid domain ] It works great if there is an error, however, if there is not an error, you get this other error message.--> if error? error: try [send [doug--vos--eds--com] {test} ][ ; this will probably NOT force an error log-event/error system/script/header/file "error" (disarm error) ; and I'll get your test message ] ** Script Error: error needs a value. ** Where: if error? error: try [ send [doug--vos--eds--com] {test} ] Because error does not receive a value when it interprets " error: try " -- since there is not an error. So then I tried... if error? error: try [send [joe--blow--gogogo--com] {test} (disarm error) ][ ; not in the book, but I was just trying stuff log-event/error system/script/header/file "error" (disarm error) ] This is bad because the script runs for a while but it is constantly disarming error that never really occured.... This sort of works but fills up my log file with junk and then eventually the program crashes with a garbage collection error. Douglas Vos - EDS/GM-BSU Webmaster e-Mail: mailto:[doug--vos--eds--com]

 [2/5] from: kgd03011:nifty:ne:jp at: 4-Aug-2000 0:17


Hi Doug, Why don't you try it this way: if error? error: try [send [doug--vos--eds--com] {test} true ][ log-event/error system/script/header/file "error" (disarm error) ] SEND doesn't return a value, so TRY doesn't return one either. As a result all the set-word error: sees is the unset! value, which produces the error. If you add 'true to the end of the try block, that ensures you'll have some value to set 'error to. Here's an illustration with PRINT, another function that returns no value.
>> type? try [print "hello"]
hello == unset!
>> error? try [print "hello"] ; ERROR? doesn't mind unset!
hello == false
>> error? error: try [print "hello"] ; but error: can't stand it
hello ** Script Error: error needs a value. ** Where: error? error: try [print "hello"]
>> error? error: try [print "hello" true] ; give it TRUE to keep it happy
hello == false See you, Eric

 [3/5] from: doug:vos:eds at: 3-Aug-2000 11:18


Thanks! Just prior to getting your email, I tried putting (error: none) right after send... in the block. It works also. So I hope this saves some other soul some frustration. In fact I can just put: yes, or no, or none - just so that try will return some value. You are correct in pointing out that send returns "no value" at all, since even returning none, makes the function work. if error? error: try [send [doug--vos--eds--com] {test} yes ][ log-event/error system/script/header/file "error" (disarm error) ]

 [4/5] from: rebol:techscribe at: 3-Aug-2000 10:51


Hi Douglas, 1. to correct that problem use set/any 'error try [...] 2. Why don't you join the REBOL ... Guide mailing list? I think that will be a better forum for discussing book related issues, so as not to waste the bandwidth for people who haven't bought the book. 3. BTW, the RTOG list is open to anyone, whether they've bought the book or not (in case you want to monitor the discussions there, to decide if the book is something that may come in handy.) You can sign up for the list http://www.TechScribe.com Hope this helps, At 10:06 AM 8/3/00 -0400, you wrote:
>I have read and re-read the sections >REBOL the official guide. about errors.
<<quoted lines omitted: 30>>
>Douglas Vos - EDS/GM-BSU Webmaster >e-Mail: mailto:[doug--vos--eds--com]
;- Elan [ : - ) ] author of REBOL: THE OFFICIAL GUIDE REBOL Press: The Official Source for REBOL Books http://www.REBOLpress.com visit me at http://www.TechScribe.com

 [5/5] from: rebol:techscribe at: 3-Aug-2000 10:59


Hi Eric,
>SEND doesn't return a value, so TRY doesn't return one either. As a >result all the set-word error: sees is the unset! value, which produces >the error.
Exactly.
>If you add 'true to the end of the try block, that >ensures you'll have some value to set 'error to.
1. A better way to do it would be to use set/any 'error try [...] as in:
>> either error? set/any 'error try [print "hi"] [
print "error" ] [ print "no error" ] hi no error
>> either error? set/any 'error try [print 1 / 0] [
print "error" ] [ print "no error" ] error ;- Elan [ : - ) ] author of REBOL: THE OFFICIAL GUIDE REBOL Press: The Official Source for REBOL Books http://www.REBOLpress.com visit me at http://www.TechScribe.com

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted