catch and throw functions

For the Compleat Fan
Locked
dukester
Posts: 115
Joined: Tue May 08, 2007 1:06 pm
Location: Alberta, Canada

catch and throw functions

Post 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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post 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
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

dukester
Posts: 115
Joined: Tue May 08, 2007 1:06 pm
Location: Alberta, Canada

Post 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.

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

Glad to be of service ;)
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Locked