Re: catch and eval
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: catch and eval

From: mark anthony <koyama80@gmail.com>
Date: Wed Dec 21 2005 - 11:53:33 CET

why catch it at all? puts wont fail you

your foo is nothing more then puts -nonewline with more arguments

so this would do the same
::proc out { args } { ::return [::puts [::join $args ""] ] }

use eval and expr with care and love your curly brace.

what happend ?

[catch "eval puts $args" msg]

"eval puts $args" will be subst'ed to "eval puts hi there"
since "" denotes string

catch is catch skript ?varName?

so your "eval puts hi there" will be executed like

eval { eval puts hi there }

ok that the eval is useless was pointed out already but
i hope at least now you see what went doo
puts is called with 2 arguments so it assumes 'hi' is
a channel therefor the error msg

as said dont use " but { and }, i hope you see now
why.

so conclusion just write your normal code that might
sometimes fail as normal but like that

::if {[::catch {
   codeline1
   codeline2
} msg]} then {
   puts "error: $msg"
}

in some cases you might rather use if {[info .... ]} then { code }
rather then catch as you may find catch slower then info if it
fails often.

cheers,
mark anthony
Received on Fri Dec 23 19:02:45 2005