Re: catch replacing useful errorInfo



TronyQ wrote:
Group,
I was wondering if there was a way to not lose the error stack trace
when using the catch command. For example:

proc read_data {args} {
if {[catch {gen_data} msg]} { error $msg }
}

The best answer requires Tcl 8.5:

package require Tcl 8.5
proc read_data {args} {
if {[catch {gen_data} msg options]} {
return -options $options $msg
}
}

If you need to support Tcl 8.4 (or earlier):

package require Tcl 8.0
proc read_data {args} {
if {[catch {gen_data} msg]} {
error $msg $::errorInfo $::errorCode
}
}

DGP

.



Relevant Pages

  • Re: doubt in tcl
    ... Most of the Tcl OO extensions are ... is just a proc or tcl command that implements the instance of the ... proc $newInstance {method args} ...
    (comp.lang.tcl)
  • Re: de-listing a list to use as proc arguments
    ... TCL proc. ... Or I can write it using "args" and call it in this way: ... applying it as arguments to a proc. ...   proc reduce { ...
    (comp.lang.tcl)
  • Re: -? or -h command option support in Tcl-core
    ... mind, is: ... proc test {arg1 arg2 args} ... > current versions of tcl, to be able to use or adopt the currently ...
    (comp.lang.tcl)
  • Re: Namespace confusion
    ... > variables outside of the namespace eval (just in case there is a global with ... using the variable command in a proc has a side effect. ... proc create:namespace {ns args} \ ... for each "set" Tcl searches the current ...
    (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)