Posted to tcl by sebres at Tue Sep 17 18:55:25 GMT 2019view pretty

# ---------------------------------------------------
# 1.a catch is main command - catch is in call stack:
# ---------------------------------------------------

% catch { \
  \
  \
  proc foo {} { \
    \
    \
    error test
  }
  foo
}; puts $::errorInfo

test
    while executing
"error test"
    (procedure "foo" line 1)
    invoked from within
"foo"
    invoked from within
"catch { \
  \
  \
  proc foo {} { \
    \
    \
    error test
  }
  foo
}"

# ---------------------------------------------------
# 1.b now put eval around - catch is NOT in call stack:
# ---------------------------------------------------
% eval {catch { \
  \
  \
  proc foo {} { \
    \
    \
    error test
  }
  foo
}; puts $::errorInfo}

test
    while executing
"error test"
    (procedure "foo" line 1)
    invoked from within
"foo"

# =======================================================================================

# ---------------------------------------------------
# 2. info frame vs. proc - [info frame] is in line 4, [error] in line 1
# ---------------------------------------------------

% eval {catch { \
  \
  \
  proc foo {} { \
    \
    \
    error [info frame 0]
  }
  foo
}; puts $::errorInfo}

type proc line 4 cmd {info frame 0} proc ::foo level 0
    while executing
"error [info frame 0]"
    (procedure "foo" line 1)
    invoked from within
"foo"

# =======================================================================================

# ---------------------------------------------------
# 3.1 file - error in file, line 9
# ---------------------------------------------------

$ echo '\
  \
  \
  proc foo {} { \
    \
    \
    error test
  }
  foo
' > /tmp/test | ./tcltest /tmp/test

test
    while executing
"error test"
    (procedure "foo" line 1)
    invoked from within
"foo"
    (file "/tmp/test" line 9)

# ---------------------------------------------------
# 3.2 file (with eval around) - error in file, line 1
# ---------------------------------------------------

$ echo 'eval {\
  \
  \
  proc foo {} { \
    \
    \
    error test
  }
  foo
}' > /tmp/test | ./tcltest /tmp/test

test
    while executing
"error test"
    (procedure "foo" line 1)
    invoked from within
"foo"
    ("eval" body line 3)
    invoked from within
"eval {\
  \
  \
  proc foo {} { \
    \
    \
    error test
  }
  foo
}"
    (file "/tmp/test" line 1)