02.03.2014 Views

Tornado

Tornado

Tornado

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Tornado</strong> 2.0<br />

User’s Guide<br />

■<br />

if then else Statement: In an if command, you may omit the keyword then<br />

before the first command body; but do not omit else if there is a second<br />

command body.<br />

CORRECT: if {$id != 0} {<br />

...<br />

} else {<br />

...<br />

}<br />

INCORRECT: if {$id !=0} then {<br />

...<br />

} {<br />

...<br />

}<br />

■<br />

Return Values: Tcl procedures only return strings; whatever meaning the<br />

string has (a list for instance) is up to the application. Therefore each constant<br />

value that a procedure can return must be described in the procedure<br />

documentation, in the RETURNS: block. If a complex element is returned,<br />

provide a complete description of the element layout. Do not use the return<br />

statement to indicate that an abnormal situation has occurred; use the error<br />

statement in that situation.<br />

The following illustrates a complex return value consisting of a description:<br />

# Return a list of 11 items: vxTicks taskId status priority pc<br />

# sp errno timeout entry priNormal name<br />

return [concat [lrange $tiList 0 1] [lrange $tiList 3 end]]<br />

The following illustrates and simple return value:<br />

# This code checks whether the VxMP component is installed:<br />

if [catch "wtxSymFind -name smObjPoolMinusOne" result] {<br />

if {[wtxErrorName $result] == "SYMTBL_SYMBOL_NOT_FOUND"} {<br />

return -1 # VxMP is not installed<br />

} else {<br />

error $result<br />

}<br />

} else {<br />

return 0<br />

# VxMP is installed<br />

}<br />

■<br />

Error Conditions: The Tcl error command raises an error condition that can be<br />

trapped by the catch command. If not caught, an error condition terminates<br />

script execution. For example:<br />

336

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!