In this chapter, we will cover:
catch
command eval
command error
commandAs discussed in the introduction to this book, I eventually learned the true power of the Tcl shell and how it can be used to locate and diagnose issues within the code. By using the puts
statement I was able to track changes in variables and isolate sections of the code that were presenting issues.
In this chapter we will investigate the commands built into the Tcl shell that allow for more elegant error handling and isolation of sections of code to ensure that they perform correctly before proceeding with a procedure.
Error handling within Tcl allows the developer the freedom to determine how to react to an error. In the following sections we will explore Tcl error handling by implementing these control constructs to illustrate how you can use error handling to proceed with the command without raising an error or returning a Tcl error code. Based on which error handling command you decide to use, you can react accordingly and present the end user with the desired result.
The error handling constructs are as follows:
Control construct |
Explanation |
---|---|
|
The It the |
|
The Returns the result of the evaluation. |
|
The error command generates an error and is used to create the messages to be logged or returned to the end user. |
By using error handling control constructs, we can not only determine in advance if an error might occur, but also present the end user with information or instructions on how to proceed.
18.118.37.154