-
Book Overview & Buying
-
Table Of Contents
Tcl/Tk 8.5 Programming Cookbook
In this section, we will build an error handling procedure to expand on the catch construct example presented earlier. This recipe will accept a filename and a program name. If the file exists and can be opened for reading it will attempt to open the file within the program passed. If the file can be opened but the program fails for any other reason we will display an error message of our own creation.
To complete the following example we will need to create a Tcl script file in your working directory. Open the text editor of your choice and follow the given instructions.
Using the editor of your choice, create a text file named error_handling.tcl that contains the following commands:
#Check that two arguments were passed
if { $argc == 2 } {
#Define variables for the filename, program
set fname [lindex $argv 0]
set progname [lindex $argv 1]
#Check that the file exists for reading
set retval [file readable $fname]
#If the file exists for reading...
Change the font size
Change margin width
Change background colour