Forum OpenACS Q&A: Re: Recommended way to throw errors from functions

Posted by Andrew Piskorski on
Yes, of course you can catch the Tcl error command.

David, "variable errorInfo"? Don't you mean global? I use this:

if { [catch { error "It breaks!" } errmsg] } {
   global errorInfo
   set my_error $errorInfo
   ns_log Error $my_error
In reality AOLserver Tcl globals are per-thread, so there's really no need to do the extra "set my_error" step, but the example in the Tcl docs does it like the above, so what the heck. Maybe you really need to do it that way in other Tcl environments. (E.g., maybe with multiple interpretors in the same single-threaded process, or with multiple threads in tclsh.)