Page 1 of 1

catch and throw functions

Posted: Wed Aug 15, 2007 4:00 am
by dukester
Hey...

on p19 of "Introduction-to-newLISP" the following example is given:

(catch
(for (i 0 9)
(if (= i 5) (throw (string "i was " i)) )
(print i " ")
)
)

For some reason, the above does not print "i was 5", yet it does print the correct output. What am I missing? TIA...
--
dukester

Posted: Wed Aug 15, 2007 12:15 pm
by Jeff
Because "i was 5" is the value of the catch. It was not caught into any symbol, so there was no output. If you run it inside the repl, the entire expression will evaluate to "i was 5", but only the print statement will print things out.

Here is a more comprehensive tutorial I wrote on newLisp error handling and flow control using catch/throw:

http://artfulcode.nfshost.com/files/sim ... wlisp.html

Posted: Thu Aug 16, 2007 5:57 am
by dukester
Jeff wrote:Because "i was 5" is the value of the catch. It was not caught into any symbol, so there was no output. If you run it inside the repl, the entire expression will evaluate to "i was 5", but only the print statement will print things out.

Here is a more comprehensive tutorial I wrote on newLisp error handling and flow control using catch/throw:

http://artfulcode.nfshost.com/files/sim ... wlisp.html
Thanks for the URL. Nice article!! Helped a lot.

Posted: Thu Aug 16, 2007 11:55 am
by Jeff
Glad to be of service ;)