info errorstack

info errorstack

This subcommand of info returns the -errorstack field from the option dictionary trapped at the last catch or try.

errorstack for Tcl 8.5

HaO 2012-09-07 As errorstack is a tcl 8.6 extension, one may simulate it with the following code for tcl 8.5. I got this code from Alexandre Ferrieux on clt and it is far to complex for me. Alexandre has also fixed the bug which prevents using this code for before tcl 8.5.9.

if {[package vsatisfies [info patchlevel] 8.5.10-8.6]} {
    set ::errorLevel -1
    set ::errorStack {}
    
    trace add variable ::errorInfo write {
        set __n [info level]
        if {![regexp {\n    invoked from within\n} $::errorInfo]} {
            set ::errorLevel -1;
            set ::errorStack [list];
        }        
        if {($__n > 0) && ($__n != $::errorLevel)} {
            set ::errorLevel $__n
            set __l [info level 0]
            lappend ::errorStack $__l
        }
        list
    }
}