Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a tcl script running through the end if there is failure in a command in the script

Status
Not open for further replies.

tpham1002002

Technical User
Jun 20, 2012
6
0
0
US
I am creating a TCL script namely test.tcl in that script I use many built-in Tcl commands to test a tool in batch mode. This is contents of the script, for example

a $myname
b $last $first
c $occupation

where a, b and c are Tcl built-in commands
somehow the variables are passing incorrectly and cause one of the commands failure (for example command b will fail if $first is empty string) then it will stops the script running through the end.
I am thinking a way to keep the test.tcl script running through the end in that case and report the error if there is any but I dont know how to do that.
I guess I need to have a check in each command to capture the error if it fails but it is beyond my knowledge since I just learn Tcl.
I would like to have your help to help me to resolve the issue.
Thanks a lot
Tony
 
Posttpham1002002 I've had this problem too. The 'catch' procedure can be used to catch errors. The way I've used is:
set errorval {}
catch {tclscripts} errorval
Here, if tclscript does not generate an error the errorval variable will be blank. If there is an error the errorval will contain some script. The program will just continue and you can interrogate the variable an any time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top