Well, here is an area where Tcl doesn't make it as easy as it could. The exit code of an exec'ed program is available, but not in a straightforward manner.
When an error occurs in Tcl, it stores values in a couple of pre-defined global variables. One of those is errorInfo, which gets a stack...