errorCode

$errorCode, a variable managed by Tcl, contains the value of the -errorcode entry in the options dictionary that describes the last error encountered.

See Also

error
errorInfo
TIP #287: Add a Commands for Determining Size of Buffered Data , comp.lang.tcl, 2006-12-14
$errorCode is also discussed.

Description

return creates an options dictionary which made available via catch and try. For convenience, when the evaluation of a command produces an error code, it is also written to $::errorCode.

DKF writes in Interrupting loops:

The global errorCode variable is probably the best way to detect what kind of error happened; all too often it is shamefully ignored by the majority of scripts, and yet it is far easier for scripts to handle it than the errorInfo variable or the message string itself.

One way to encourage setting the errorCode would be to propose additional error classes. The standard ARITH, CHILD*, NONE, and POSIX only cover a fraction of all possible error conditions.