trace error



Hi,

I am using TCL for some years now, and I think I am familiar with it's
tracing, introspection, and overall error handling techniques.

But there is one thing I find curious and I would like to ask you, if there happens to be a part of the API (TCL or C) that I have overlooked.

Whenever an error occurres in my script the interpreter unwinds the call stack to the point where either the error is catch'ed or the top level is reached. But if I want to know exactly under which circumstances the bad thing happened, it would be way helpful if I could "do something" before the stack unwinding takes place. Like some sort of call-me-first hook procedure. This way I could determine the names and values of all local variables which were used at the time of the error. Or even snapshot ALL variables, local or namespace, to generate a detailed error report.

Example:

proc A {val} {
if {[catch {B $val} msg]} {
puts "B failed because of '$msg'"
#
# I can handle B's error here, but I know nothing
# about the local (to proc B) variable 'x' and 'y'. It's gone
# already.
#
}
}

proc B {x} {
set y [incr x]; error if $x is not integer
return [expr {17 / $x}]; error if $x is zero
}

A -1


Of course I can always use catch. But if I want to make sure I am notified of every possible TCL error before the stack unwinds, I would have to wrap catch around every single proc in my program.

So the functionality I am looking for is the capability to "trace" errors.

In the same lines as "trace add variable" or "trace add command" can register procedures which are called before or after something happens to a variable or proc, "trace error callbackProc" would register the name of a proc to be called when an error occurres, before the stack unwinds, and would be executed in the same frame in which the error occurred.


So I would like to know:

1. Can this behavior be implemented using the current API?
2. If not, could this be filed as a TIP?
3. Is there anybody who cares? ;)

Regards,
Tobias Hippler
.



Relevant Pages

  • Re: trace error
    ... But there is one thing I find curious and I would like to ask you, if there happens to be a part of the API (TCL or C) that I have overlooked. ... proc A { ... But if I want to make sure I am notified of every possible TCL error before the stack unwinds, I would have to wrap catch around every single proc in my program. ... In the same lines as "trace add variable" or "trace add command" can register procedures which are called before or after something happens to a variable or proc, "trace error callbackProc" would register the name of a proc to be called when an error occurres, before the stack unwinds, and would be executed in the same frame in which the error occurred. ...
    (comp.lang.tcl)
  • Re: function and structures
    ... C code and i have to rewrite the code in TcL. ... is to assign to it with a set command (or some other commands such ... probably the best way is to use a Tcl array. ... Functions are declared with the proc command: ...
    (comp.lang.tcl)
  • Re: function and structures
    ... lines,, i want to implement the same in TcL. ... is to assign to it with a set command (or some other commands such ... probably the best way is to use a Tcl array. ... Functions are declared with the proc command: ...
    (comp.lang.tcl)
  • Re: Call flow - tcl - menu ivr - array as fsm? better than if?
    ... number i've dialed, execute the TCL script. ... TCL would play prompts and, in the end and if applicable, transfer the ... Router calls the tcl script that is located on a machine which is ... proc act_Setup { ...
    (comp.lang.tcl)
  • [PROBLEM] 2.4.23-pre4 deadlocks while 2.4.22aa1 works fine
    ... Proc; keventd ... Trace; c011af8e ... Proc; kdeinit ... Proc; bash ...
    (Linux-Kernel)