Re: catch replacing useful errorInfo



Bryan Oakley wrote:
Donald G Porter wrote:

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
}
}

Interesting. You advocate "error .." over "return -code error ...". Is there a technical reason or just a personal preference?

In this case my key reason was greater similarity to what the
OP was already doing.

Usually for me, the choice between [return -code error] vs [error]
should rest on whether the intent is to report back to the caller
that the arguments it passed you are unacceptable, or whether it's
really something internal to your own code that's going wrong. In
this instance, that choice also leads to [error].

Note that there's an assumption underlying this, that the OP really
has something more sophisticated in mind than the example he posted,
because for that example the best answer is to just not [catch]
in the first place.

DGP
.



Relevant Pages