This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

catch question/error ??

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

catch question/error ??

Post by Ofloo »

Code: Select all

if {[string match -nocase *k* $packet(size)]} {
  catch {[format %.2f [expr [lindex [split [string tolower $packet(size)] k] 0] * 1024.0]]} packet(byte)
} elseif {[string match -nocase *m* $packet(size)]} {
  catch {[format %.2f [expr [lindex [split [string tolower $packet(size)] m] 0] * 1024 * 1024.0]]} packet(byte)
} elseif {[string match -nocase *g* $packet(size)]} {
  catch {[format %.2f [expr [lindex [split [string tolower $packet(size)] g] 0] * 1024 * 1024 * 1024.0]]} packet(byte)
} elseif {[string match -nocase *b* $packet(size)]} {
  catch {[format %.2f [lindex [split [string tolower $packet(size)] b] 0]]} packet(byte)
}
putlog "$packet(byte)"
error: [18:06] <Eggy> [18:06] invalid command name "5368709120.00"
catch script ?varName?
so the last one is setting the varname right ..? ex: catch [expr 1+2] result
putlog $result -- > result = 3 right ??

why then is it giving that error ?
Last edited by Ofloo on Thu Feb 05, 2004 1:25 pm, edited 1 time in total.
XplaiN but think of me as stupid
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Because catch executes the code you pass it... if you are calling

catch [expr 1+2] blah

Then tcl first does substitution...

catch 3 blah

Then tcl tries to execute "3", and gets an error. You probably meant:

catch {expr 1+2} blah
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

but why.. how can a variable be executed ?

so how can i prevent it from executing i just wana set something and catch it in case it goes wrong ..
XplaiN but think of me as stupid
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

"expr" is a command, not a variable...

as for your second question, use the code that I showed you already :)
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

sorry ic what u mean .. lol think i understand now tnx
XplaiN but think of me as stupid
Locked