Error

The error command raises an error condition that terminates a script unless it is trapped with the catch command. The command takes up to three arguments:

error message ?info? ?code?
					

The message becomes the error message stored in the result variable of the catch command.

If the info argument is provided, then the Tcl interpreter uses this to initialize the errorInfo global variable. That variable is used to collect a stack trace from the point of the error. If the info argument is not provided, then the error command itself is used to initialize the errorInfo trace.

Example 6-17 Raising an error.
proc foo {} {
   error bogus
}
foo
=> bogus
set errorInfo
=> bogus
						while executing
						"error bogus"
						(procedure "foo" line 2)
						invoked from within ...

Get Practical Programming in Tcl & Tk, Third Edition 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.