Using the error command

The primary usage of the error command is to programmatically raise an error. This allows you to interrupt the interpreter at the desired point and to present the user with an error message of your choice.

Getting ready

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.

How to do it…

In the following example, to illustrate, we will generate an error and a supporting error message in a location where it should not occur. Using the editor of your choice, create a text file named error.tcl that contains the following commands:

if {1+1==2} {
error "My Error"
}

After you have created the file, invoke the script ...

Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.