catch and throw functions

Started by dukester, August 14, 2007, 09:00:29 PM

Previous topic - Next topic

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
duke

Jeff

#1
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/simple-error-handling-in-newlisp.html">//http://artfulcode.nfshost.com/files/simple-error-handling-in-newlisp.html
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

dukester

#2
Quote from: "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/simple-error-handling-in-newlisp.html">//http://artfulcode.nfshost.com/files/simple-error-handling-in-newlisp.html


Thanks for the URL. Nice article!! Helped a lot.
duke

Jeff

#3
Glad to be of service ;)
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code